updates.
[crypto.git] / lib / silcclient / client_ftp.c
index 494923b19a6077ed3e5a184316f3048ba5999921..1f19f94567e106c4bfa5a39a9cdffba9be2cd3f4 100644 (file)
@@ -49,6 +49,7 @@ struct SilcClientFtpSessionStruct {
   SilcClientFileMonitor monitor;
   void *monitor_context;
   char *filepath;
+  char *path;
 
   SilcSFTP sftp;
   SilcSFTPFilesystem fs;
@@ -265,7 +266,8 @@ static void silc_client_ftp_data(SilcSFTP sftp,
 
   /* Read more, until EOF is received */
   session->read_offset += data_len;
-  silc_sftp_read(sftp, session->read_handle, session->read_offset, 64512,
+  silc_sftp_read(sftp, session->read_handle, session->read_offset, 
+                 SILC_PACKET_MAX_LEN - 1024,
                 silc_client_ftp_data, session);
 
   /* Call monitor callback */
@@ -290,6 +292,7 @@ static void silc_client_ftp_open_handle(SilcSFTP sftp,
                                        void *context)
 {
   SilcClientFtpSession session = (SilcClientFtpSession)context;
+  char path[512];
 
   SILC_LOG_DEBUG(("Start"));
 
@@ -309,8 +312,10 @@ static void silc_client_ftp_open_handle(SilcSFTP sftp,
   }
 
   /* Open the actual local file */
-  session->fd = silc_file_open(session->filepath, 
-                              O_RDWR | O_CREAT | O_EXCL);
+  memset(path, 0, sizeof(path));
+  snprintf(path, sizeof(path) - 1, "%s%s", session->path ?
+          session->path : "", session->filepath);
+  session->fd = silc_file_open(path, O_RDWR | O_CREAT | O_EXCL);
   if (session->fd < 0) {
     /* Call monitor callback */
     session->client->internal->ops->say(session->client, session->conn, 
@@ -331,7 +336,8 @@ static void silc_client_ftp_open_handle(SilcSFTP sftp,
   session->read_handle = handle;
 
   /* Now, start reading the file */
-  silc_sftp_read(sftp, session->read_handle, session->read_offset, 64512,
+  silc_sftp_read(sftp, session->read_handle, session->read_offset,
+                 SILC_PACKET_MAX_LEN - 1024,
                 silc_client_ftp_data, session);
 
   /* Call monitor callback */
@@ -377,7 +383,7 @@ static void silc_client_ftp_readdir_name(SilcSFTP sftp,
   silc_sftp_open(sftp, name->filename[0], SILC_SFTP_FXF_READ, &attr,
                 silc_client_ftp_open_handle, session);
 
-  /* Save the important attributes */
+  /* Save the important attributes like filename and file size */
   session->filepath = strdup(name->filename[0]);
   session->filesize = name->attrs[0]->size;
 
@@ -540,7 +546,7 @@ static void silc_client_ftp_start_key_agreement(SilcClientFtpSession session,
                        NULL, session->monitor_context);
 
   /* Add new connection for this session */
-  conn = silc_client_add_connection(client, session->hostname,
+  conn = silc_client_add_connection(client, NULL, session->hostname,
                                    session->port, session);
 
   /* Allocate new socket connection object */
@@ -638,7 +644,7 @@ SILC_TASK_CALLBACK(silc_client_ftp_process_key_agreement)
                        NULL, session->monitor_context);
 
   /* Add new connection for this session */
-  conn = silc_client_add_connection(client, newsocket->hostname,
+  conn = silc_client_add_connection(client, NULL, newsocket->hostname,
                                    newsocket->port, session);
   conn->sock = newsocket;
   conn->sock->user_data = conn;
@@ -752,7 +758,7 @@ void silc_client_ftp_session_free(SilcClientFtpSession session)
       if (conn->active_session == session)
        conn->active_session = NULL;
 
-      silc_client_close_connection(session->client, session->sock, conn);
+      silc_client_close_connection_real(session->client, session->sock, conn);
     } else {
       silc_socket_free(session->sock);
     }
@@ -889,6 +895,7 @@ silc_client_file_receive(SilcClient client,
                         SilcClientConnection conn,
                         SilcClientFileMonitor monitor,
                         void *monitor_context,
+                        const char *path,
                         SilcUInt32 session_id)
 {
   SilcClientFtpSession session;
@@ -918,6 +925,7 @@ silc_client_file_receive(SilcClient client,
   session->monitor = monitor;
   session->monitor_context = monitor_context;
   session->conn = conn;
+  session->path = path ? strdup(path) : NULL;
 
   /* If the hostname and port already exists then the remote client did
      provide the connection point to us and we won't create listener, but