I recently used the FTP function to upload files. Code Write down and make a mark.
Use support. dll. download it from here.
You need to reference this DLL before using it, and then using ftpsupport;
The following is the FTP upload code: /**/ /// <Summary>
/// FTP upload
/// </Summary>
/// <Param name = "localfile"> Such as server. mappath ("~ /") +" Log.txt" </Param>
/// <Param name = "Dr"> Name of the FTP server directory, for example,/vagerent/image/ </Param>
/// <Param name = "newremotefile"> The name of the file that is uploaded to the server, such as log.txt. </Param>
/// <Returns> </returns>
Private Int Ftpfile ( String Localfile, String Dr, String Newremotefile)
{
String Remotedr = " / " ;
Ftpconnection FTP = New Ftpconnection ();
Try
{
String Ftpip = Configurationsettings. deleettings [ " Ftpip " ];
String Ftpusrname = Configurationsettings. deleettings [ " Ftpusrname " ];
String Ftpusrpsw = Configurationsettings. deleettings [ " Ftpusrpsw " ];
FTP. Connect (ftpip, ftpusrname, ftpusrpsw );
Remotedr = Dr;
FTP. setcurrentdirectory (remotedr );
FTP. putfile (localfile, newremotefile );
Return 1 ; // Uploaded
}
Catch (Exception ERR)
{
Return 0;//Upload Failed
}
Finally
{
FTP. Close ();
}
}