[CSharp] SFTP

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, "경고");
	}
}

이전글
다음글

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 항목은 *(으)로 표시합니다