Michele Bersani showed a very simple example of FTP uploader using a third party library (in .NET 1.1 you don’t have any FTP support at all) and hence I wrote a Python version.
Here is his script: [code lang="java"] using System; using System.IO; using EnterpriseDT.Net.Ftp;
namespace SimpleFTP
{
class Simple
{
[STAThread]
static void Main(string[] args)
{
try
{
FTPClient ftp = new FTPClient();
// Host
ftp.RemoteHost = "Host";
// Connect
ftp.Connect();
// Login
ftp.Login("User", "Password");
// Set up connect and transfer modes
ftp.ConnectMode = FTPConnectMode.ACTIVE;
ftp.TransferType = FTPTransferType.ASCII;
// Put file to remote server
ftp.Put("local_file", "remote_file");
// Close connection
ftp.Quit();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.ReadLine();
}
}
}
[/code]
and this is mine (1 to 1 example, don’t bother with proper error handling):
[code lang="python"] import os from ftplib import FTP
try: # login to the remote host ftp_client = FTP("host") ftp_client.login("username", "password")
# change dir
ftp_client.cwd("remotepath")
# open the local file in ASCII mode
f = open("localfile", "r")
# upload file in lines mode
ftp_client.storlines('STOR %s' % os.path.basename("localfile"), f)
f.close()
# disconnect
ftp_client.quit()
except e: print e [/code]
In .NET 2.0 (finally) they put some FTP support in: System.Net.FtpWebRequest




One Trackback/Pingback
E’ venerdi sera e io sono un geek del cavolo