从命令行我可以使用
成功通过FTP连接到我的主机ftp.domain.com or domain.com
C:\Users\Aaron>ftp
ftp> open
To domain.com
Connected to domain.com.
220 FTP Server ready.
User (domain.com:(none)): Login failed.
ftp> close
221 Goodbye.
ftp> open
To ftp.domain.com
Connected to ftp.domain.com.
220 FTP Server ready.
User (ftp.domain.com:(none)): Login failed.
ftp> close
221 Goodbye.
ftp> quit
我转义了上面的密码并清理了域名,但它仍然显示每个连接我都成功了。当我在Visual Studio中运行此代码时,我得到了无效的URI。
这是我在C#中试过的代码
Uri target = new Uri("ftp://ftp.domain.com/");
FtpWebRequest requestDir = (FtpWebRequest)FtpWebRequest.Create(target);
requestDir.Credentials = new NetworkCredential("user", "pass");
Uri target = new Uri("ftp://ftp.domain.com/");
FtpWebRequest requestDir = (FtpWebRequest)FtpWebRequest.Create(target);
requestDir.Credentials = new NetworkCredential("user", "pass");
请求的URI对此FTP命令无效
我已经在这里看过,因为有很多这样的人,但是我已经尝试了所有这些(我想),我只是继续犯这个错误。有什么想法吗?
谢谢!
答案 0 :(得分:0)
我能够通过这里的其他一些帖子帮助它并进行大量的故障排除。我现在有这个工作,并已转移到新的错误。以下是成功上传FTP的代码:
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();