1: public void FXP()
2: {
3: //FXP, aka site-to-site or server-to-server transfers
4: //not commonly supported by FTP servers by default, for
5: //security reasons
6:
7: string[] portdata = null;
8: Ftp ftpA = new Ftp();
9: ftpA.Timeout = 5;
10: ftpA.OnPITrail += new Ftp.OnPITrailHandler(delegate(object sender, FtpPITrailEventArgs e)
11: {
12: if (e.Message.StartsWith("227")) //response to PASV
13: {
14: string portparams = e.Message.Substring(e.Message.IndexOf("(") + 1);
15: portparams = portparams.Remove(portparams.IndexOf(")"));
16: portdata = portparams.Split(new char[] { ',' });
17: }
18: });
19: ftpA.RemoteHost = "serverA";
20: ftpA.User = "test";
21: ftpA.Password = "password";
22: ftpA.Passive = true;
23: ftpA.Logon();
24: ftpA.Command = "PASV";
25: //if this reply was 200 OK, then the server will allow the site to site transfer.
26:
27: //now we know the port number that server A is listening on (portparams),
28: //so start a retriever on server B:
29: ThreadPool.QueueUserWorkItem(new WaitCallback(FTPRetriever), portdata);
30:
31: //start the sender on server A:
32: ftpA.Command = "STOR uploaded.txt\r\n"; //the file to create on server 1
33:
34: //done..disconnect
35: ftpA.Logoff();
36: }
37:
38: static void FTPRetriever(object parameter)
39: {
40: string[] portdata = (string[])parameter;
41: Ftp ftpB = new Ftp();
42: ftpB.Timeout = 5;
43: ftpB.RemoteHost = "serverB";
44: ftpB.User = "test";
45: ftpB.Password = "mypassword";
46: ftpB.Passive = false;
47: ftpB.Logon();
48: ftpB.RemotePath = "destinationfolder/";
49: ftpB.ListDirectory();
50:
51: ftpB.Command = "PORT " + portdata[0] + "," + portdata[1] + "," + portdata[2] + "," +
52: portdata[3] + "," + portdata[4] + "," + portdata[5];
53: ftpB.Command = "RETR uploaded.txt"; //the file to get from server A
54: ftpB.Logoff();
55: }