1

I am trying to upload files in the FTP server I have been using the FtpWebrequest. At default, the port is 21. I need to upload using port 22. I have tried adding port 22 in the URI itself. But i get an error while reaching GetRequestStream() method. The error message is

The underlying connection is closed. The server committed a protocol violation

My code looks like below

Dim request = DirectCast(FtpWebRequest.Create("ftp://absd.com:22/inbox/xxx.dat"), FtpWebRequest)
request.Method = WebRequestMethods.Ftp.UploadFile
request.Credentials = New NetworkCredential(userID,pwd)
request.UseBinary = True
request.UsePassive = True
Dim bytes() As Byte = File.ReadAllBytes(sourceFilePath)
request.ContentLength = bytes.Length
Using uploadstream As Stream = request.GetRequestStream()
    uploadstream.Write(bytes, 0, bytes.Length)
    uploadstream.Close()
End Using

Let me know what have I missed.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992

1 Answers1

2

Port 22 is for SSH/SFTP. That's not FTP. So you cannot use FtpWebRequest.

There's no SFTP implementation in .NET. You have to use a 3rd party library.

See also:

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992