private void SubirImagen(string file, string codigo) { Chilkat.Ftp2 ftp = new Chilkat.Ftp2(); bool success; ftp.Hostname = "www.repuestosdemoviles.es"; ftp.Username = "******"; ftp.Password = "******"; success = ftp.Connect(); if (success != true) { Console.WriteLine(ftp.LastErrorText); return; } string cwd = "httpdocs/ebay/imagenes/" + codigo.Trim(); string BaseUrl = "http://www.repuestosdemoviles.es/ebay/imagenes/" + codigo.Trim(); success = ftp.ChangeRemoteDir(cwd); success = ftp.PutFile(file, Path.GetFileName(file)); if (success != true) { Console.WriteLine(ftp.LastErrorText); return; } ftp.Disconnect(); }
/// <summary> /// FtpInternalSendFile() --> Performs an FTP Upload. /// </summary> /// <param name="cust">Indicates the name of supplier portal customer.</param> /// <param name="app">Indicates the name of eFlow application.</param> /// <param name="fn">Indicates the name of the file to upload.</param> /// <param name="fnUp">Indicates the name of the file on the server (how it will be called once uploaded).</param> /// <param name="folder">Indicates the folder where the file will be uploaded</param> /// <param name="hostname">Indicates the host name where the file will be uploaded</param> /// <param name="username">Indicates the name of the user allowed to login into the hostname</param> /// <param name="pwd">Indicates the password of the user allowed to login into the hostname</param> /// <example><code>s.FtpInternalSendFile("topimagesystems.com", "CLS", "00000323.tif", "/images", "ftp.doksend.com", "supplierportaluser", "e7low5!!");</code></example> protected bool FtpInternalSendFile(string cust, string app, string fn, string fnUp, string folder, string hostname, string username, string pwd) { bool result = false; try { using (Chilkat.Ftp2 ftp = new Chilkat.Ftp2()) { if (ftp.UnlockComponent(Constants.cStrChilkatFtpLic)) { ftp.Hostname = hostname; ftp.Username = username; ftp.Password = pwd; ftp.Passive = true; if (ftp.Connect()) { if (ftp.ChangeRemoteDir(folder)) { if (ftp.GetSizeByName(fnUp) < 0) { if (File.Exists(fn)) { result = ftp.PutFile(fn, fnUp); Thread.Sleep(50); } } } } else { Logging.WriteLog(ftp.LastErrorText); } ftp.Disconnect(); } } } catch (Exception ex) { Logging.WriteLog(ex.ToString()); } return(result); }
void m_bgWorker_DoWork(object sender, DoWorkEventArgs e) { // Indicate that we are in the background thread // The FTP object's event callback will need this. m_bgRunning = true; // We passed the filename as an argument. // However, we could've just as well accessed the filename // via the txtFilename textbox control. string filename = e.Argument as string; // Is this an upload or download? if (m_isUpload) { // This causes both AbortCheck and FtpPercentDone events to // fire. The callback methods are m_ftp_OnAbortCheck and // m_ftp_OnFtpPercentDone. These methods in turn call the // m_bgWorker.ReportProgress method, causing the // m_bgWorker_ProgressChanged to be called. The progress // bars can only be updated from a background thread // in the m_bgWorker_ProgressChanged event. The same applies // to any other Form controls. bool success = m_ftp.PutFile(filename, filename); e.Result = success; } else { bool success = m_ftp.GetFile(filename, filename); e.Result = success; } // Display the last-error and session log regardless of success/failure... m_ftpLastError = m_ftp.LastErrorText; m_ftpSessionLog = m_ftp.SessionLog; m_bgRunning = false; return; }
static void Main(string[] args) { GenerarArchivo(); Console.WriteLine("archivo generado con exito"); Console.ReadKey(); Chilkat.Global glob = new Chilkat.Global(); bool successUnlock = glob.UnlockBundle("Anything for 30-day trial"); if (successUnlock != true) { Console.WriteLine(glob.LastErrorText); return; } int status = glob.UnlockStatus; if (status == 2) { Console.WriteLine("Unlocked using purchased unlock code."); } else { Chilkat.Ftp2 ftp = new Chilkat.Ftp2(); ftp.Hostname = "localhost"; ftp.Username = "******"; ftp.Password = "******"; // Connect and login to the FTP server. bool success = ftp.Connect(); if (success != true) { Console.WriteLine(ftp.LastErrorText); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); return; } // Change to the remote directory where the file will be uploaded. success = ftp.ChangeRemoteDir("doc"); if (success != true) { Console.WriteLine(ftp.LastErrorText); return; } // Upload a file. string localPath = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName) + @"\prueba.txt"; string remoteFilename = "prueba.txt"; success = ftp.PutFile(localPath, remoteFilename); if (success != true) { Console.WriteLine(ftp.LastErrorText); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); return; } success = ftp.Disconnect(); Console.WriteLine("File Uploaded!"); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); } }