我想通过FTP使用以下脚本上传文件。该文件确实上传到FTP服务器,但文件名称始终被称为图像,并且没有exstenion。FTP文件上传问题 - 缺少文件名
它可能是一些简单的我已经错过了,但如果有人知道它会出错哪里会有所帮助。
public static string _FTPusername = "xx";
public static string _FTPPassword = "xxxxx";
public static string _FTPServerAddress = "cp.domainname.co.uk";
public static string _ftpurl = "ftp://cp.domainname.co.uk/Images"; //= "ftp://cp.domainname.co.uk/Images";
try
{
string filename = Path.GetFileName(source);
string ftpfullpath = ConnectionDetails._ftpurl;
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
ftp.Credentials = new NetworkCredential(ConnectionDetails._FTPusername, ConnectionDetails._FTPPassword);
ftp.KeepAlive = true;
ftp.UseBinary = true;
ftp.Method = WebRequestMethods.Ftp.UploadFile;
FileStream fs = File.OpenRead(source);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
Stream ftpstream = ftp.GetRequestStream();
ftpstream.Write(buffer, 0, buffer.Length);
ftpstream.Close();
}
catch(Exception ex)
{
throw ex;
}
我你不使用你的文件名可变的任何地方看到了什么? – 2012-04-01 21:22:31