[CSharp] SFTP

CSharp
ConnectionInfo ci = new ConnectionInfo(SFTP_HOST, SFTP_PORT, SFTP_USER, new PasswordAuthenticationMethod(SFTP_USER, SFTP_PASS)); using (var sftpClient = new SftpClient(ci)) { try { // sftpClient.KeepAliveInterval = TimeSpan.FromSeconds(60); sftpClient.ConnectionInfo.Timeout = TimeSpan.FromMinutes(180); sftpClient.OperationTimeout = TimeSpan.FromMinutes(180); sftpClient.Connect(); sftpClient.DeleteFile(SFTP_PATH); sftpClient.Disconnect(); // sftpClient.Connect(); sftpClient.BufferSize = 4 * 1024; using (FileStream fs = new FileStream(LOCAL_FILE, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { sftpClient.BufferSize = 4 * 1024; sftpClient.UploadFile(fs, FILE_NAME, true); } sftpClient.Disconnect(); // sftpClient.Connect(); sftpClient.DownloadFile(SFTP_DOWNLOAD_SERVER_PATH, LOCAL_FILE); sftpClient.Disconnect(); } catch (System.Net.Sockets.SocketException socket_ex) { MessageBox.Show(socket_ex.Message, "경고"); } catch (Renci.SshNet.Common.SshAuthenticationException ssh_ex) { MessageBox.Show(ssh_ex.Message, "경고"); } }
Read More