comparison lib/sshv2.c @ 537:c568539856d2

2004-8-17 Brian Masney <masneyb@gftp.org> * lib/sshv2.c - added sshv2_open_file(). sshv2_get_file() and sshv2_put_file() now use this function
author masneyb
date Wed, 18 Aug 2004 03:19:23 +0000
parents 65cd664cbf32
children ee182b8d1a54
comparison
equal deleted inserted replaced
536:9fa452580f94 537:c568539856d2
1734 1734
1735 return (size); 1735 return (size);
1736 } 1736 }
1737 1737
1738 1738
1739 static off_t 1739 static int
1740 sshv2_get_file (gftp_request * request, const char *file, int fd, 1740 sshv2_open_file (gftp_request * request, const char *file, off_t startsize,
1741 off_t startsize) 1741 guint32 mode)
1742 { 1742 {
1743 char *tempstr, *endpos; 1743 char *tempstr, *endpos;
1744 sshv2_params * params; 1744 sshv2_params * params;
1745 sshv2_message message; 1745 sshv2_message message;
1746 guint32 num; 1746 guint32 num;
1748 int ret; 1748 int ret;
1749 1749
1750 g_return_val_if_fail (request != NULL, GFTP_EFATAL); 1750 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
1751 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL); 1751 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL);
1752 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL); 1752 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL);
1753 /* fd ignored for this protocol */
1754 1753
1755 params = request->protocol_data; 1754 params = request->protocol_data;
1756 params->offset = startsize; 1755 params->offset = startsize;
1757 1756
1758 len = 8; 1757 len = 8;
1759 tempstr = sshv2_initialize_string_with_path (request, file, &len, &endpos); 1758 tempstr = sshv2_initialize_string_with_path (request, file, &len, &endpos);
1760 1759
1761 num = htonl (SSH_FXF_READ); 1760 num = htonl (mode);
1762 memcpy (endpos, &num, 4); 1761 memcpy (endpos, &num, 4);
1763 1762
1764 ret = sshv2_send_command (request, SSH_FXP_OPEN, tempstr, len); 1763 ret = sshv2_send_command (request, SSH_FXP_OPEN, tempstr, len);
1765 1764
1766 g_free (tempstr); 1765 g_free (tempstr);
1782 return (GFTP_ERETRYABLE); 1781 return (GFTP_ERETRYABLE);
1783 1782
1784 } 1783 }
1785 1784
1786 memset (params->handle, 0, 4); 1785 memset (params->handle, 0, 4);
1787 memcpy (params->handle + 4, message.buffer+ 4, message.length - 5); 1786 memcpy (params->handle + 4, message.buffer + 4, message.length - 5);
1788 params->handle_len = message.length - 1; 1787 params->handle_len = message.length - 1;
1788 printf ("FIXME - handle len is %d\n", params->handle_len);
1789 sshv2_message_free (&message); 1789 sshv2_message_free (&message);
1790
1791 return (0);
1792 }
1793
1794
1795 static off_t
1796 sshv2_get_file (gftp_request * request, const char *file, int fd,
1797 off_t startsize)
1798 {
1799 int ret;
1800
1801 if ((ret = sshv2_open_file (request, file, startsize, SSH_FXP_OPEN)) < 0)
1802 return (ret);
1790 1803
1791 return (sshv2_get_file_size (request, file)); 1804 return (sshv2_get_file_size (request, file));
1792 } 1805 }
1793 1806
1794 1807
1795 static int 1808 static int
1796 sshv2_put_file (gftp_request * request, const char *file, int fd, 1809 sshv2_put_file (gftp_request * request, const char *file, int fd,
1797 off_t startsize, off_t totalsize) 1810 off_t startsize, off_t totalsize)
1798 { 1811 {
1799 char *tempstr, *endpos; 1812 guint32 mode;
1800 sshv2_params * params;
1801 sshv2_message message;
1802 size_t len, num;
1803 int ret; 1813 int ret;
1804 1814
1805 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
1806 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL);
1807 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL);
1808 /* fd ignored for this protocol */
1809
1810 params = request->protocol_data;
1811 params->offset = startsize;
1812
1813 len = 8;
1814 tempstr = sshv2_initialize_string_with_path (request, file, &len, &endpos);
1815
1816 if (startsize > 0) 1815 if (startsize > 0)
1817 num = htonl (SSH_FXF_WRITE | SSH_FXF_CREAT | SSH_FXF_APPEND); 1816 mode = SSH_FXF_WRITE | SSH_FXF_CREAT | SSH_FXF_APPEND;
1818 else 1817 else
1819 num = htonl (SSH_FXF_WRITE | SSH_FXF_CREAT | SSH_FXF_TRUNC); 1818 mode = SSH_FXF_WRITE | SSH_FXF_CREAT | SSH_FXF_TRUNC;
1820 memcpy (endpos, &num, 4); 1819
1821 1820 if ((ret = sshv2_open_file (request, file, startsize, mode)) < 0)
1822 ret = sshv2_send_command (request, SSH_FXP_OPEN, tempstr, len); 1821 return (ret);
1823
1824 g_free (tempstr);
1825 if (ret < 0)
1826 return (ret);
1827
1828 ret = sshv2_read_status_response (request, &message, -1, SSH_FXP_STATUS,
1829 SSH_FXP_HANDLE);
1830 if (ret < 0)
1831 return (ret);
1832
1833 if (message.length - 4 > SSH_MAX_HANDLE_SIZE)
1834 {
1835 request->logging_function (gftp_logging_error, request,
1836 _("Error: Message size %d too big from server\n"),
1837 message.length - 4);
1838 sshv2_message_free (&message);
1839 gftp_disconnect (request);
1840 return (GFTP_ERETRYABLE);
1841
1842 }
1843
1844 memset (params->handle, 0, 4);
1845 memcpy (params->handle + 4, message.buffer + 4, message.length - 5);
1846 params->handle_len = message.length - 1;
1847 sshv2_message_free (&message);
1848 1822
1849 return (0); 1823 return (0);
1850 } 1824 }
1851 1825
1852 1826