Mercurial > gftp.yaz
comparison lib/sshv2.c @ 500:ba50a7085d93
2004-7-13 Brian Masney <masneyb@gftp.org>
* lib/gftp.h lib/local.c lib/protocols.c lib/rfc2068.c lib/rfc959.c
lib/sshv2.c - added gftp_stat_filename(). This will retrieve the
attributes for the selected file. When downloading a list of items,
if one of the items is a symlink, check to see if it points to a
directory or file
* src/gtk/misc-gtk.c - fix for displaying the folder icon for
directories
author | masneyb |
---|---|
date | Wed, 14 Jul 2004 02:33:42 +0000 |
parents | 39e9945288ea |
children | fbb5a02beddb |
comparison
equal
deleted
inserted
replaced
499:39e9945288ea | 500:ba50a7085d93 |
---|---|
1209 | 1209 |
1210 if (attrs & SSH_FILEXFER_ATTR_PERMISSIONS) | 1210 if (attrs & SSH_FILEXFER_ATTR_PERMISSIONS) |
1211 { | 1211 { |
1212 if ((num = sshv2_buffer_get_int32 (request, message, -1)) < 0) | 1212 if ((num = sshv2_buffer_get_int32 (request, message, -1)) < 0) |
1213 return (num); | 1213 return (num); |
1214 | |
1215 fle->st_mode = num; | |
1214 } | 1216 } |
1215 | 1217 |
1216 if (attrs & SSH_FILEXFER_ATTR_ACMODTIME) | 1218 if (attrs & SSH_FILEXFER_ATTR_ACMODTIME) |
1217 { | 1219 { |
1218 if ((num = sshv2_buffer_get_int32 (request, message, -1)) < 0) | 1220 if ((num = sshv2_buffer_get_int32 (request, message, -1)) < 0) |
1227 if (attrs & SSH_FILEXFER_ATTR_EXTENDED) | 1229 if (attrs & SSH_FILEXFER_ATTR_EXTENDED) |
1228 { | 1230 { |
1229 if ((count = sshv2_buffer_get_int32 (request, message, -1)) < 0) | 1231 if ((count = sshv2_buffer_get_int32 (request, message, -1)) < 0) |
1230 return (GFTP_EFATAL); | 1232 return (GFTP_EFATAL); |
1231 | 1233 |
1232 printf ("FIXME - file %d extended attributes\n", count); | |
1233 for (i=0; i<count; i++) | 1234 for (i=0; i<count; i++) |
1234 { | 1235 { |
1235 if ((num = sshv2_buffer_get_int32 (request, message, -1)) < 0 || | 1236 if ((num = sshv2_buffer_get_int32 (request, message, -1)) < 0 || |
1236 message->pos + num + 4 > message->end) | 1237 message->pos + num + 4 > message->end) |
1237 return (GFTP_EFATAL); | 1238 return (GFTP_EFATAL); |
1670 | 1671 |
1671 return (0); | 1672 return (0); |
1672 } | 1673 } |
1673 | 1674 |
1674 | 1675 |
1676 static int | |
1677 sshv2_send_stat_command (gftp_request * request, const char *filename, | |
1678 gftp_file * fle) | |
1679 { | |
1680 sshv2_message message; | |
1681 char *tempstr; | |
1682 gint32 len; | |
1683 int ret; | |
1684 | |
1685 g_return_val_if_fail (request != NULL, GFTP_EFATAL); | |
1686 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL); | |
1687 g_return_val_if_fail (filename != NULL, GFTP_EFATAL); | |
1688 | |
1689 len = 0; | |
1690 tempstr = sshv2_initialize_string_with_path (request, filename, &len, NULL); | |
1691 | |
1692 ret = sshv2_send_command (request, SSH_FXP_STAT, tempstr, len); | |
1693 | |
1694 g_free (tempstr); | |
1695 if (ret < 0) | |
1696 return (ret); | |
1697 | |
1698 ret = sshv2_read_status_response (request, &message, -1, SSH_FXP_STATUS, | |
1699 SSH_FXP_ATTRS); | |
1700 if (ret < 0) | |
1701 return (ret); | |
1702 | |
1703 if (message.length < 5) | |
1704 return (GFTP_EFATAL); | |
1705 | |
1706 message.pos += 4; | |
1707 if ((ret = sshv2_decode_file_attributes (request, &message, fle)) < 0) | |
1708 { | |
1709 gftp_file_destroy (fle); | |
1710 return (ret); | |
1711 } | |
1712 | |
1713 sshv2_message_free (&message); | |
1714 | |
1715 return (0); | |
1716 } | |
1717 | |
1718 | |
1719 static mode_t | |
1720 sshv2_stat_filename (gftp_request * request, const char *filename) | |
1721 { | |
1722 gftp_file fle; | |
1723 mode_t ret; | |
1724 | |
1725 memset (&fle, 0, sizeof (fle)); | |
1726 ret = sshv2_send_stat_command (request, filename, &fle); | |
1727 if (ret < 0) | |
1728 return (ret); | |
1729 | |
1730 ret = fle.st_mode; | |
1731 gftp_file_destroy (&fle); | |
1732 | |
1733 return (ret); | |
1734 } | |
1735 | |
1736 | |
1675 static off_t | 1737 static off_t |
1676 sshv2_get_file_size (gftp_request * request, const char *file) | 1738 sshv2_get_file_size (gftp_request * request, const char *file) |
1677 { | 1739 { |
1678 sshv2_message message; | |
1679 gftp_file fle; | 1740 gftp_file fle; |
1680 char *tempstr; | 1741 off_t size; |
1681 int serv_ret; | 1742 int ret; |
1682 gint32 len; | 1743 |
1683 off_t ret; | 1744 memset (&fle, 0, sizeof (fle)); |
1684 | 1745 ret = sshv2_send_stat_command (request, file, &fle); |
1685 g_return_val_if_fail (request != NULL, GFTP_EFATAL); | |
1686 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL); | |
1687 g_return_val_if_fail (file != NULL, GFTP_EFATAL); | |
1688 | |
1689 len = 0; | |
1690 tempstr = sshv2_initialize_string_with_path (request, file, &len, NULL); | |
1691 | |
1692 ret = sshv2_send_command (request, SSH_FXP_STAT, tempstr, len); | |
1693 | |
1694 g_free (tempstr); | |
1695 if (ret < 0) | 1746 if (ret < 0) |
1696 return (ret); | 1747 return (ret); |
1697 | 1748 |
1698 serv_ret = sshv2_read_status_response (request, &message, -1, SSH_FXP_STATUS, | 1749 size = fle.size; |
1699 SSH_FXP_ATTRS); | |
1700 if (serv_ret < 0) | |
1701 return (serv_ret); | |
1702 | |
1703 if (message.length < 5) | |
1704 return (GFTP_EFATAL); | |
1705 | |
1706 message.pos += 4; | |
1707 memset (&fle, 0, sizeof (fle)); | |
1708 if ((serv_ret = sshv2_decode_file_attributes (request, &message, &fle)) < 0) | |
1709 { | |
1710 gftp_file_destroy (&fle); | |
1711 return (serv_ret); | |
1712 } | |
1713 | |
1714 ret = fle.size; | |
1715 gftp_file_destroy (&fle); | 1750 gftp_file_destroy (&fle); |
1716 sshv2_message_free (&message); | 1751 |
1717 | 1752 return (size); |
1718 return (ret); | |
1719 | |
1720 } | 1753 } |
1721 | 1754 |
1722 | 1755 |
1723 static off_t | 1756 static off_t |
1724 sshv2_get_file (gftp_request * request, const char *file, int fd, | 1757 sshv2_get_file (gftp_request * request, const char *file, int fd, |
2045 request->transfer_file = NULL; | 2078 request->transfer_file = NULL; |
2046 request->get_next_file_chunk = sshv2_get_next_file_chunk; | 2079 request->get_next_file_chunk = sshv2_get_next_file_chunk; |
2047 request->put_next_file_chunk = sshv2_put_next_file_chunk; | 2080 request->put_next_file_chunk = sshv2_put_next_file_chunk; |
2048 request->end_transfer = sshv2_end_transfer; | 2081 request->end_transfer = sshv2_end_transfer; |
2049 request->abort_transfer = sshv2_end_transfer; /* NOTE: uses sshv2_end_transfer */ | 2082 request->abort_transfer = sshv2_end_transfer; /* NOTE: uses sshv2_end_transfer */ |
2083 request->stat_filename = sshv2_stat_filename; | |
2050 request->list_files = sshv2_list_files; | 2084 request->list_files = sshv2_list_files; |
2051 request->get_next_file = sshv2_get_next_file; | 2085 request->get_next_file = sshv2_get_next_file; |
2052 request->get_next_dirlist_line = NULL; | 2086 request->get_next_dirlist_line = NULL; |
2053 request->get_file_size = sshv2_get_file_size; | 2087 request->get_file_size = sshv2_get_file_size; |
2054 request->chdir = sshv2_chdir; | 2088 request->chdir = sshv2_chdir; |