I am trying to upload files via FTP using the following script. The file does upload to the FTP server however the file name is always called Images and has no exstenion.
Its probably something simple i have missed but if anyone know where it is going wrong that would be help.
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;
}