c# sftp 업로드 에러 질문이요..

try
{
using (var client = new SftpClient(host, port, username, password))
{
client.ConnectionInfo.Timeout = TimeSpan.FromSeconds(sftpalivetimeinseconds);
client.Connect();
if (client.IsConnected)
{
Debug.WriteLine(“I’m connected to the client”);

                    using (var fileStream = new FileStream(newSubFolderPath, FileMode.Open))
                    {
                        client.BufferSize = 4 * 1024; // bypass Payload error large files
                        var remoteFileName = Path.GetFileNameWithoutExtension(newSubFolderPath);
                        client.UploadFile(fileStream, remoteFileName);
                    }
                }
                else
                {
                    Debug.WriteLine("I couldn't connect");
                }
            }
        }
        catch (Renci.SshNet.Common.SshConnectionException ex)
        {
            Debug.WriteLine($"An error occurred: {ex.Message}");
            Debug.WriteLine($"SSH connection error: {ex.InnerException?.Message}");
        }
        catch (Exception ex)
        {
            Debug.WriteLine($"An error occurred: {ex.Message}");
        }
    }

이런 식으로 sftp 로 업로드를 하려고 합니다.(2023 03 21 예제 코드 다시 올림)

그런데 업로드 하려고 하면 “channel was closed” 라는 에러 메시지가 뜨는데요…

어떤 부분을 확인해서 수정하면 되는지 알려주시면 감사하겠습니다

2개의 좋아요

File.Open()으로 SFTP 프로토콜을 사용할 수 없는 것으로 알고 있습니다.


sftpClient이군요. 잘못 답변하였네요.

2개의 좋아요

sftpClient 가 닫힌거 아닌가요 ?
sftpClient 의 Status 확인 해 보셨나요 ?

1개의 좋아요

답변 감사합니다 확인해볼게요

1개의 좋아요

답변 감사합니다!! sftpclient 연결 상태 확인해볼게요!!

1개의 좋아요

해당 sftp 서버로 파일을 업로드 하고 나면 바로 서버를 끊어버려서
channel was closed 라는 에러 메세지가 뜨는 거였네요…!

3개의 좋아요