"Requested Uri Is Invalid" During Upload with Ftpwebrequest

The requested URI is invalid for this FTP command

If you just want to check file information you should try changing the request.Method to WebRequestMethods.Ftp.ListDirectoryDetails instead:

WebRequest request = WebRequest.Create("ftp://myftp.com");
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
request.Credentials = new NetworkCredential("myusername", "12344");
using (var resp = (FtpWebResponse)request.GetResponse())
{
Console.WriteLine(resp.StatusCode);
}

requested url is invalid for this ftp command

I had same problem once and I replaced "ftp://100.100.100.83/" with "ftp://ftp.xxx.com/" and works fine.

your URL missing the file name,

ftp://100.100.100.83/blacklist.csv

FtpWebRequest request is triggering a Invalid URI format

I was able to get it working with the help of some other posts here and a lot of troubleshooting. I now have this working and have moved on to new errors. Here is the code for the successful FTP upload:

reqCakes = (FtpWebRequest)WebRequest.Create("ftp://domain.com/images/" + "koala.jpg");
reqCakes.UseBinary = true;
reqCakes.Method = WebRequestMethods.Ftp.UploadFile;
reqCakes.Credentials = new NetworkCredential("user", "pass");
BinaryReader rdrCakes = new BinaryReader(File.Open(fileToOpen, FileMode.Open));
rdrCakes.Close();
byte[] cakeData = File.ReadAllBytes(fileToOpen);
reqCakes.ContentLength = cakeData.Length;
Stream reqStream = reqCakes.GetRequestStream();
reqStream.Write(cakeData, 0, cakeData.Length);
reqStream.Close();

Can enter FTP using Filezilla but .NET gives The requested URI is invalid for this FTP command.

have you tryed includig the ftpfile name when creating request?

 FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpUrl+ "/" + Path.GetFileName(zipFileName));

Download file from url and upload into ftp

I think your problem is that your url is missing the file name. If I remember correctly you must pass the file name in the URL. So it would look something like this:

"ftp://192.168.1.1/SampleFiles/file.txt"

Getting Invalid URL when uploading file using FtpWebRequest

The URL does not have a form

ftp://192.168.xx.xx:FILE.TAB

but

ftp://192.168.xx.xx/FILE.TAB

See https://en.wikipedia.org/wiki/URL



Related Topics



Leave a reply



Submit