Since you behind a Proxy, and naturally behind NAT, as I know you have to use Passive Mode, you make a practical test with any FTP client.
system.net.ftpwebrequest.usepassive
The requested URI is invalid for this FTP command.
![](https://techprofile.blob.core.windows.net/images/Ha_JgLm9WEaXTgXPyIwb_Q.png?8D923B)
Vuyiswa Maseko
351
Reputation points
Good Day All
i am uploading a file via ftp behind a Proxy and my code looks like this
string HostName = "ftp://ftp.myserver.com";
string UserName = "usr;
string Password = "password;
string PureFileName = new FileInfo("TotalAmount").Name;
String uploadUrl = String.Format("{0}", HostName );
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(uploadUrl);
request.Method = WebRequestMethods.Ftp.UploadFile;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential("username", "password");
request.Proxy = null;
request.KeepAlive = true;
request.UseBinary = true;
request.Method = WebRequestMethods.Ftp.UploadFile;
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader(FullPath);
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
and when i run this i get an error
*The requested URI is invalid for this FTP command.*
i am doing this in a Windows service not a web project
Thanks
1 answer
Sort by: Most helpful
-
Jose Zero 576 Reputation points
2022-03-08T15:21:20.203+00:00