Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
FTP from .net app
Message
 
To
25/03/2010 11:26:18
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01457140
Message ID:
01457209
Views:
62
Bill,

This should get you kick started. If you install and add a reference to your project you can use the following code to send and receive via FTP:
 /// <summary>
        /// Method to take a local file and send to an FTP site
        /// </summary>
        /// <param name="localFileName"></param>
        /// <param name="remoteFileName"></param>
        /// <param name="remoteDirName"></param>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        public string SendFileViaFTP(string hostSite, string localFileName, string remoteFileName, string remoteDirName, string userName, string password)
        {
            string msg = "";
            
            FTPClient oFTP = new FTPClient();
            try
            {
                oFTP.RemoteHost = hostSite.TrimEnd();
                oFTP.Connect();
                oFTP.Login(userName.TrimEnd(), password.TrimEnd());
                if (remoteDirName.TrimEnd() != "")
                    oFTP.ChDir(remoteDirName);
                if (localFileName.Contains(".pgp"))
                    oFTP.TransferType = FTPTransferType.BINARY;
                else
                    oFTP.TransferType = FTPTransferType.ASCII;
                oFTP.Put(localFileName, remoteFileName);
            }
            catch (Exception e)
            {
                msg = e.Message;
            }
            finally
            {
                if (oFTP.Connected)
                    oFTP.Quit();
            }
            return msg;
        }
and
/// <summary>
        /// Method to retrieve a file via FTP
        /// </summary>
        /// <param name="hostSite"></param>
        /// <param name="localFileName"></param>
        /// <param name="remoteFileName"></param>
        /// <param name="remoteDirName"></param>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        public string RetrieveFileViaFTP(string hostSite, string localDirName, 
            string remoteFileName, string remoteDirName, string userName, string password)
        {
            FTPClient oFTP = new FTPClient();
            string returnMsg = "";
            try
            {
                oFTP.RemoteHost = hostSite.TrimEnd();
                oFTP.Connect();
                oFTP.Login(userName.TrimEnd(), password.TrimEnd());
                if (remoteDirName.TrimEnd() != "")
                    oFTP.ChDir(remoteDirName.TrimEnd());
                if (remoteFileName.Contains(".pgp"))
                    oFTP.TransferType = FTPTransferType.BINARY;
                else
                    oFTP.TransferType = FTPTransferType.ASCII;
                
                oFTP.Get(localDirName.TrimEnd(), remoteFileName.TrimEnd());
            }
            catch (Exception e)
            {
                returnMsg = e.Message;
            }
            finally
            {
                if (oFTP.Connected)
                    oFTP.Quit();
                returnMsg = returnMsg + " ";
            }
            return returnMsg;
        }
>Thanks Bob
>
>I downloaded the freebie and I'll try it.
>
>
>>>I have used Enterprise Distributed Technologies for FTP from my .NET application. They have a free version if you are just using regular FTP. I am using it and it works fine and is easy to use. If you want to use SFTP (secure FTP) you would have to pay for their PRO version. Here is the link:
>
>
>http://www.enterprisedt.com/products.html
>
>Hope this helps
>
>Bob
Previous
Reply
Map
View

Click here to load this message in the networking platform