working on it ...

Filters

Explore Public Snippets

Sort by

Found 762 snippets matching: ftp

    public by Fresh-Dev  218786  1  3  0

    FTP-Helper Class

    FTP-Helper Class: ftp-helper.cs
    //
    //
    //          Ftp File Helper
    //
    //
    //Funktionen: 
    //CheckConnection
    //UploadFile
    //GetFileList
    //DownloadFile
    //DeleteFile
    //CreateFolder
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Net;
    using System.IO;
    using System.Threading;
    
    class FtpHelper
    {
        #region Properties
        
        public string Adress { get; set; }
        public string User { get; set; }
        public string Password { get; set; }
    
        #endregion
    
        #region Constructor
    
        /// <summary>
        /// Initialisiert eine neue Instanz der FTP Helper Klasse
        /// </summary>
        /// <param name="adress">Name oder IP Adresse des Servers</param>
        /// <param name="user">Benutzername</param>
        /// <param name="password">Passwort</param>
        public FtpHelper(string adress, string user, string password)
        {
            this.Adress = adress;
            this.User = user;
            this.Password = password;
        }
    
        #endregion
    
        #region Events
    
        public delegate void ReceivedFileListCompleteEventhandler();
        public event ReceivedFileListCompleteEventhandler ReceivedFileListComplete;
    
        #endregion
    
        /// <summary>
        /// Überprüft ob eine Verbindung zum FTP Server besteht
        /// </summary>
        public void CheckConnection()
        {
            try
            {
                FtpWebRequest.DefaultWebProxy = null;
                FtpWebRequest ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + this.Adress + "/"));
                ftpWebRequest.Credentials = new NetworkCredential(this.User, this.Password);
    
                //Als Methode muss ListDirectory gewählt werden!
                ftpWebRequest.Method = WebRequestMethods.Ftp.ListDirectory;
    
                WebResponse webResponse = ftpWebRequest.GetResponse();
            }
            catch (Exception)
            {
                throw;
            }
        }
    
        /// <summary>
        /// Lädt Dateien auf einen FTP Server
        /// </summary>
        /// <param name="remoteFolder">Zielverzeichnis</param>
        /// <param name="fileInfo"></param>
        public void UploadFile(string remoteFolder, FileInfo fileInfo)
        {
            try
            {
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri("ftp://" + Adress + "/" + remoteFolder + "/" + fileInfo.Name));
    
                request.Method = WebRequestMethods.Ftp.UploadFile;
    
                request.Credentials = new NetworkCredential(User, Password);
    
                Stream ftpStream = request.GetRequestStream();
    
                FileStream file = File.OpenRead(fileInfo.FullName);
    
                int length = 1024;
                byte[] buffer = new byte[length];
                int bytesRead = 0;
    
                do
                {
                    bytesRead = file.Read(buffer, 0, length);
                    ftpStream.Write(buffer, 0, bytesRead);
                }
                while (bytesRead != 0);
    
                file.Close();
                ftpStream.Close();
            }
            catch (WebException)
            {
                throw;
            }
        }
    
        /// <summary>
        /// Lädt Dateien auf einen FTP Server
        /// </summary>
        /// <param name="fileInfo"></param>
        public void UploadFile(FileInfo fileInfo)
        {
            this.UploadFile("", fileInfo);
        }
    
        /// <summary>
        /// Liefert eine Liste von Dateien zurück, die sich in einem bestimmten Verzeichnis auf dem Server befinden
        /// </summary>
        /// <returns></returns>
        public List<string> GetFileList(string remoteFolder)
        {
            FtpWebRequest ftpWebRequest = (FtpWebRequest)WebRequest.Create("ftp://" + Adress + "/" + remoteFolder);
            ftpWebRequest.Method = WebRequestMethods.Ftp.ListDirectory;
    
            WebResponse webResponse = null;
    
            ftpWebRequest.Credentials = new NetworkCredential(User, Password);
    
            try
            {
                webResponse = ftpWebRequest.GetResponse();
            }
            catch (Exception)
            {
                throw;
            }
    
            List<string> files = new List<string>();
    
            StreamReader streamReader = new StreamReader(webResponse.GetResponseStream());
    
            while (!streamReader.EndOfStream)
            {
                files.Add(streamReader.ReadLine());
            }
    
            streamReader.Close();
    
            webResponse.Close();
    
            return files;
        }
    
        /// <summary>
        /// Liefert eine Liste von Dateien zurück
        /// </summary>
        /// <returns></returns>
        public List<string> GetFileList()
        {
            return this.GetFileList("");
        }
    
        /// <summary>
        /// Lädt eine Datei vom FTP Server herunter
        /// </summary>
        public void DownloadFile(string remoteFolder, FileInfo file, string destinationFolder, FileInfo destinationFile)
        {
            try
            {
                WebClient webClient = new WebClient();
    
                webClient.Credentials = new NetworkCredential(User, Password);
    
                byte[] data = webClient.DownloadData(new Uri("ftp://" + Adress + "/" + remoteFolder + "/" + file.Name));
    
                FileStream fileStream = File.Create(destinationFolder + @"\" + destinationFile);
    
                fileStream.Write(data, 0, data.Length);
    
                fileStream.Close();
            }
            catch (WebException)
            {
                throw;
            }
        }
    
        /// <summary>
        /// Lädt eine Datei vom FTP Server herunter
        /// </summary>
        /// <param name="file"></param>
        /// <param name="destinationFolder"></param>
        /// <param name="destinationFile"></param>
        public void DownloadFile(FileInfo file, string destinationFolder, FileInfo destinationFile)
        {
            this.DownloadFile("", file, destinationFolder, destinationFile);
        }
    
        /// <summary>
        /// Löscht eine Datei vom FTP Server
        /// </summary>
        /// <param name="remoteFolder">Zielverzeichnis</param>
        /// <param name="fileInfo">Datei</param>
        public void DeleteFile(string remoteFolder, FileInfo fileInfo)
        {
            try
            {
                FtpWebRequest ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + Adress + "/" + remoteFolder + "/" + fileInfo.Name));
                ftpWebRequest.UseBinary = true;
                ftpWebRequest.Credentials = new NetworkCredential(User, Password);
                ftpWebRequest.Method = WebRequestMethods.Ftp.DeleteFile;
                ftpWebRequest.Proxy = null;
                ftpWebRequest.KeepAlive = false;
                ftpWebRequest.UsePassive = false;
                ftpWebRequest.GetResponse();
            }
            catch (Exception)
            {
                throw;
            }
        }
    
        /// <summary>
        /// Löscht eine Datei vom FTP Server
        /// </summary>
        /// <param name="fileInfo">Datei</param>
        public void DeleteFile(FileInfo fileInfo)
        {
            DeleteFile("", fileInfo);
        }
    
        /// <summary>
        /// Erstellt einen Order auf dem FTP Server in einem beliebigen Unterverzeichnis
        /// </summary>
        /// <param name="remoteFolder">Zielverzeichnis</param>
        /// <param name="folder">Verzeichnisname</param>
        public void CreateFolder(string remoteFolder, string folder)
        {
            try
            {
                FtpWebRequest ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + Adress + "/" + remoteFolder + "/" + folder));
                ftpWebRequest.UseBinary = true;
                ftpWebRequest.Credentials = new NetworkCredential(User, Password);
                ftpWebRequest.Method = WebRequestMethods.Ftp.MakeDirectory;
                ftpWebRequest.Proxy = null;
                ftpWebRequest.KeepAlive = false;
                ftpWebRequest.UsePassive = false;
                ftpWebRequest.GetResponse();
            }
            catch (Exception)
            {
                throw;
            }
        }
    
        /// <summary>
        /// Erstellt einen Ordner im Root Verzeichnis des FTP Nutzers
        /// </summary>
        /// <param name="folder">Verzeichnisname</param>
        public void CreateFolder(string folder)
        {
            this.CreateFolder("", folder);
        }
    }
    
    

    public by maholtz  2514  1  6  0

    ftp in einem bash skript verwenden

    #!/bin/bash
    
    HOST=server
    USER=benutzer
    PASS=passwort
    
    # -i deaktiviert Interaktivität
    # -n Deaktiviert auto-login, andernfalls kann in ~/.netrc das Login hinterlegt werden
    # Alle weiteren Zeilen zwischen << EOF und EOF werden innerhalb der FTP-Verbindung übergeben
    ftp -in $HOST << EOF
    
    # Einloggen
    user $USER $PASS
    
    # Hier folgen die Befehle
    cd /files
    
    # die Datei "datei.txt" die an der Stelle liegt, wo das FTP
    # Programm ausgeführt wurde, wird auf den Server in 
    # das Verzeichnis /files kopiert.
    put datei.txt
    
    # Oder andersrum: /files/datei.txt wird herunterkopiert
    get datei.txt
    # mit bye wird die Verbindung beendet.
    # EOF (end of file) schließt die Eingabe an das FTP
    # Programm wiederab
    bye
    EOF  

    public by bkozora  779  0  3  0

    Bash - FTP Upload

    Bash - FTP Upload: bash-ftp-upload.sh
    #!/bin/sh
    
    # FTP Server
    HOST='server.address'
    
    # FTP Username
    USER='username'
    
    # FTP Password
    PASSWD='ftp.password'
    
    # Original system filename to transfer
    FILE='file.to.transfer.txt'
    
    # System directory original file is in
    DIR=`pwd`"/dir/"
    
    # FTP directory file should be saved in
    FTPDIR='ftpdir/'
    
    # Store our date in format of month.day.year-hour.minute.second
    DATE=$(date +"%m.%d.%Y-%H.%M.%S")
    
    # Filename to rename system file to
    NEWFILE='einvoice-'$DATE'.txt'
    
    # Email address to send error reporting to
    ADMINEMAIL='admin@email.com'
    
    # See who the current system user is
    # echo `whoami`
    
    # See what our current directory is
    # echo `pwd`
    
    # Change working directory to $DIR
    cd $DIR
    
    # Make sure the system file exists
    if [ -f "$DIR$FILE" ]
    then
        echo "Attempting to upload $DIR$FILE"
        
        # FTP command to execute. This will transer the $FILE then try to download it to
        # verify that it was successfully uploaded
        ftp -nv $HOST > $DIR/ftp.log.txt <<ENDSCRIPT
        quote USER $USER
        quote PASS $PASSWD
        passive
        cd $FTPDIR
        put $FILE
        get $FILE INVOICE2.$$.TXT
        bye
        quit
    ENDSCRIPT
    
        # Make sure our downloaded FTP file exists, meaning the transfer was successful
        if [ -f $DIR"INVOICE2.$$.TXT" ]
        then
            # Delete the temporary download verification file
            rm $DIR"INVOICE2.$$.TXT"
    
            # Move/rename the original file to a filename that contains today's date for backup
            mv "$DIR$FILE" "$DIR$NEWFILE"
    
            # Print some information on the sceen
            echo "FTP of $DIR$FILE to $HOST worked. File renamed from $DIR$FILE to $DIR$NEWFILE"
    
        # Our FTP verification file doesn't exist. The transfer failed.
        else
            RESULT="FTP of $DIR$FILE to $HOST did not work"
            echo $RESULT
    
            (echo "FTP File Upload to Tungsten Failed!!"; cat ftp.failed.txt) | mailx -s "Tungsten FTP File Upload Failed" $ADMINEMAIL                
    
        fi
    fi
    
    # Our local file to upload doesn't exist
    #else
    #    echo "Local file ($DIR$FILE) doesn't exist"
    #    (echo "FTP File Upload to Tungsten Failed!! Source file was not found"; cat ftp.failed.txt) | mailx -s "Tungsten FTP File Doesn't Exist" $ADMINEMAIL
    #fi
    
    exit 0
    
    

    public by AbhishekGhosh  119  1  2  -1

    mysql backup and upload to FTP

    mysql backup and upload to FTP: backup.sh
    #!/bin/bash
    
    ############### Infos - Edit them accordingly  ########################
    
    DATE=`date +%Y-%m-%d_%H%M`
    LOCAL_BACKUP_DIR="/backups"
    DB_NAME="database_name"
    DB_USER="root"
    DB_PASSWORD="root_password"
    
    FTP_SERVER="111.111.111.111"
    FTP_USERNAME="ftp-user"
    FTP_PASSWORD="ftp-pass"
    FTP_UPLOAD_DIR="/upload"
    
    LOG_FILE=/backups/backup-DATE.log
    
    ############### Local Backup  ########################
    
    mysqldump -u $DB_USER  -p$DB_PASSWORD $DB_NAME | gzip  > $LOCAL_BACKUP_DIR/$DATE-$DB_NAME.sql.gz
    
    ############### UPLOAD to FTP Server  ################
    
    ftp -nv $FTP_SERVER << EndFTP
    user "$FTP_USERNAME" "$FTP_PASSWORD"
    binary
    cd $FTP_UPLOAD_DIR
    lcd $LOCAL_BACKUP_DIR
    put "$DATE-$DB_NAME.sql.gz"
    bye
    EndFTP
    
    ############### Check and save log, also send an email  ################
    
    if test $? = 0
    then
        echo "Database Successfully Uploaded to the Ftp Server!"
        echo -e "Database Successfully created and uploaded to the FTP Server!" | mail -s "Backup from $DATE" your_email@email.com
    
    else
        echo "Error in database Upload to Ftp Server" > $LOG_FILE
    fi
    
    

    public by LongBeard  1615  2  3  0

    FTP-Helper Class

    FTP-Helper Class: ftp-helper.cs
    //
    //
    //          Ftp File Helper
    //
    //
    //Funktionen: 
    //CheckConnection
    //UploadFile
    //GetFileList
    //DownloadFile
    //DeleteFile
    //CreateFolder
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Net;
    using System.IO;
    using System.Threading;
    
    class FtpHelper
    {
        #region Properties
        
        public string Adress { get; set; }
        public string User { get; set; }
        public string Password { get; set; }
    
        #endregion
    
        #region Constructor
    
        /// <summary>
        /// Initialisiert eine neue Instanz der FTP Helper Klasse
        /// </summary>
        /// <param name="adress">Name oder IP Adresse des Servers</param>
        /// <param name="user">Benutzername</param>
        /// <param name="password">Passwort</param>
        public FtpHelper(string adress, string user, string password)
        {
            this.Adress = adress;
            this.User = user;
            this.Password = password;
        }
    
        #endregion
    
        #region Events
    
        public delegate void ReceivedFileListCompleteEventhandler();
        public event ReceivedFileListCompleteEventhandler ReceivedFileListComplete;
    
        #endregion
    
        /// <summary>
        /// Überprüft ob eine Verbindung zum FTP Server besteht
        /// </summary>
        public void CheckConnection()
        {
            try
            {
                FtpWebRequest.DefaultWebProxy = null;
                FtpWebRequest ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + this.Adress + "/"));
                ftpWebRequest.Credentials = new NetworkCredential(this.User, this.Password);
    
                //Als Methode muss ListDirectory gewählt werden!
                ftpWebRequest.Method = WebRequestMethods.Ftp.ListDirectory;
    
                WebResponse webResponse = ftpWebRequest.GetResponse();
            }
            catch (Exception)
            {
                throw;
            }
        }
    
        /// <summary>
        /// Lädt Dateien auf einen FTP Server
        /// </summary>
        /// <param name="remoteFolder">Zielverzeichnis</param>
        /// <param name="fileInfo"></param>
        public void UploadFile(string remoteFolder, FileInfo fileInfo)
        {
            try
            {
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri("ftp://" + Adress + "/" + remoteFolder + "/" + fileInfo.Name));
    
                request.Method = WebRequestMethods.Ftp.UploadFile;
    
                request.Credentials = new NetworkCredential(User, Password);
    
                Stream ftpStream = request.GetRequestStream();
    
                FileStream file = File.OpenRead(fileInfo.FullName);
    
                int length = 1024;
                byte[] buffer = new byte[length];
                int bytesRead = 0;
    
                do
                {
                    bytesRead = file.Read(buffer, 0, length);
                    ftpStream.Write(buffer, 0, bytesRead);
                }
                while (bytesRead != 0);
    
                file.Close();
                ftpStream.Close();
            }
            catch (WebException)
            {
                throw;
            }
        }
    
        /// <summary>
        /// Lädt Dateien auf einen FTP Server
        /// </summary>
        /// <param name="fileInfo"></param>
        public void UploadFile(FileInfo fileInfo)
        {
            this.UploadFile("", fileInfo);
        }
    
        /// <summary>
        /// Liefert eine Liste von Dateien zurück, die sich in einem bestimmten Verzeichnis auf dem Server befinden
        /// </summary>
        /// <returns></returns>
        public List<string> GetFileList(string remoteFolder)
        {
            FtpWebRequest ftpWebRequest = (FtpWebRequest)WebRequest.Create("ftp://" + Adress + "/" + remoteFolder);
            ftpWebRequest.Method = WebRequestMethods.Ftp.ListDirectory;
    
            WebResponse webResponse = null;
    
            ftpWebRequest.Credentials = new NetworkCredential(User, Password);
    
            try
            {
                webResponse = ftpWebRequest.GetResponse();
            }
            catch (Exception)
            {
                throw;
            }
    
            List<string> files = new List<string>();
    
            StreamReader streamReader = new StreamReader(webResponse.GetResponseStream());
    
            while (!streamReader.EndOfStream)
            {
                files.Add(streamReader.ReadLine());
            }
    
            streamReader.Close();
    
            webResponse.Close();
    
            return files;
        }
    
        /// <summary>
        /// Liefert eine Liste von Dateien zurück
        /// </summary>
        /// <returns></returns>
        public List<string> GetFileList()
        {
            return this.GetFileList("");
        }
    
        /// <summary>
        /// Lädt eine Datei vom FTP Server herunter
        /// </summary>
        public void DownloadFile(string remoteFolder, FileInfo file, string destinationFolder, FileInfo destinationFile)
        {
            try
            {
                WebClient webClient = new WebClient();
    
                webClient.Credentials = new NetworkCredential(User, Password);
    
                byte[] data = webClient.DownloadData(new Uri("ftp://" + Adress + "/" + remoteFolder + "/" + file.Name));
    
                FileStream fileStream = File.Create(destinationFolder + @"\" + destinationFile);
    
                fileStream.Write(data, 0, data.Length);
    
                fileStream.Close();
            }
            catch (WebException)
            {
                throw;
            }
        }
    
        /// <summary>
        /// Lädt eine Datei vom FTP Server herunter
        /// </summary>
        /// <param name="file"></param>
        /// <param name="destinationFolder"></param>
        /// <param name="destinationFile"></param>
        public void DownloadFile(FileInfo file, string destinationFolder, FileInfo destinationFile)
        {
            this.DownloadFile("", file, destinationFolder, destinationFile);
        }
    
        /// <summary>
        /// Löscht eine Datei vom FTP Server
        /// </summary>
        /// <param name="remoteFolder">Zielverzeichnis</param>
        /// <param name="fileInfo">Datei</param>
        public void DeleteFile(string remoteFolder, FileInfo fileInfo)
        {
            try
            {
                FtpWebRequest ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + Adress + "/" + remoteFolder + "/" + fileInfo.Name));
                ftpWebRequest.UseBinary = true;
                ftpWebRequest.Credentials = new NetworkCredential(User, Password);
                ftpWebRequest.Method = WebRequestMethods.Ftp.DeleteFile;
                ftpWebRequest.Proxy = null;
                ftpWebRequest.KeepAlive = false;
                ftpWebRequest.UsePassive = false;
                ftpWebRequest.GetResponse();
            }
            catch (Exception)
            {
                throw;
            }
        }
    
        /// <summary>
        /// Löscht eine Datei vom FTP Server
        /// </summary>
        /// <param name="fileInfo">Datei</param>
        public void DeleteFile(FileInfo fileInfo)
        {
            DeleteFile("", fileInfo);
        }
    
        /// <summary>
        /// Erstellt einen Order auf dem FTP Server in einem beliebigen Unterverzeichnis
        /// </summary>
        /// <param name="remoteFolder">Zielverzeichnis</param>
        /// <param name="folder">Verzeichnisname</param>
        public void CreateFolder(string remoteFolder, string folder)
        {
            try
            {
                FtpWebRequest ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + Adress + "/" + remoteFolder + "/" + folder));
                ftpWebRequest.UseBinary = true;
                ftpWebRequest.Credentials = new NetworkCredential(User, Password);
                ftpWebRequest.Method = WebRequestMethods.Ftp.MakeDirectory;
                ftpWebRequest.Proxy = null;
                ftpWebRequest.KeepAlive = false;
                ftpWebRequest.UsePassive = false;
                ftpWebRequest.GetResponse();
            }
            catch (Exception)
            {
                throw;
            }
        }
    
        /// <summary>
        /// Erstellt einen Ordner im Root Verzeichnis des FTP Nutzers
        /// </summary>
        /// <param name="folder">Verzeichnisname</param>
        public void CreateFolder(string folder)
        {
            this.CreateFolder("", folder);
        }
    }
    
    

    public by msdn  104619  0  6  0

    ParseRecordString: Get an FTPFileSystem from the recordString.

    Get an FTPFileSystem from the recordString.
    using System;
    using System.Text.RegularExpressions;
    using System.Text;
    
    /// <summary>
    /// Get an FTPFileSystem from the recordString. 
    /// </summary>
    public static FTPFileSystem ParseRecordString(Uri baseUrl, string recordString, FTPDirectoryListingStyle type)
    {
        FTPFileSystem fileSystem = null;
    
        if (type == FTPDirectoryListingStyle.UNIX)
        {
            fileSystem = ParseUNIXRecordString(recordString);
        }
        else
        {
            fileSystem = ParseMSDOSRecordString(recordString);
        }
    
        // Add "/" to the url if it is a directory
        fileSystem.Url = new Uri(baseUrl, fileSystem.Name + (fileSystem.IsDirectory ? "/" : string.Empty));
    
        return fileSystem;
    }

    public by msdn  1360  0  6  0

    GetFtpPath: Converts the specified path into a valid FTP file system path

    Converts the specified path into a valid FTP file system path The file system path A path formatted for FTP
    using System;
    using System.Globalization;
    using System.Text.RegularExpressions;
    
    /// <summary>
    /// Converts the specified path into a valid FTP file system path
    /// </summary>
    /// <param name="path">The file system path</param>
    /// <returns>A path formatted for FTP</returns>
    public static string GetFtpPath(this string path)
    {
        if (string.IsNullOrEmpty(path))
            return "./";
    
        path = Regex.Replace(path.Replace('\\', '/'), "[/]+", "/").Trim('/');
    
        path = "/" + path;
    
        return path;
    }

    public by msdn  1299  0  7  0

    GetFtpDate: Tries to convert the string FTP date representation into a date time object

    Tries to convert the string FTP date representation into a date time object The date UTC/Local Time A date time object representing the date, DateTime.MinValue if there was a problem
    using System;
    using System.Globalization;
    using System.Text.RegularExpressions;
    
    /// <summary>
    /// Tries to convert the string FTP date representation  into a date time object
    /// </summary>
    /// <param name="date">The date</param>
    /// <param name="style">UTC/Local Time</param>
    /// <returns>A date time object representing the date, DateTime.MinValue if there was a problem</returns>
    public static DateTime GetFtpDate(this string date, DateTimeStyles style)
    {
        string[] formats = new string[]
            {
                "yyyyMMddHHmmss",
                "yyyyMMddHHmmss.fff",
                "MMM dd  yyyy",
                "MMM dd HH:mm"
            };
        DateTime parsed;
    
        if (DateTime.TryParseExact(date, formats, CultureInfo.InvariantCulture, style, out parsed))
        {
            return parsed;
        }
    
        return DateTime.MinValue;
    }

    public by msdn  1168  0  6  0

    GetDirectoryListingStyle: Find out the FTP Directory Listing Style from the recordString.

    Find out the FTP Directory Listing Style from the recordString.
    using System;
    using System.Text.RegularExpressions;
    using System.Text;
    
    /// <summary>
    /// Find out the FTP Directory Listing Style from the recordString.
    /// </summary>
    public static FTPDirectoryListingStyle GetDirectoryListingStyle(string recordString)
    {
        Regex regex = new System.Text.RegularExpressions.Regex(@"^[d-]([r-][w-][x-]){3}$");
    
        string header = recordString.Substring(0, 10);
    
        // If the style is UNIX, then the header is like "drwxrwxrwx".
        if (regex.IsMatch(header))
        {
            return FTPDirectoryListingStyle.UNIX;
        }
        else
        {
            return FTPDirectoryListingStyle.MSDOS;
        }
    }

    public by msdn  1127  0  7  0

    GetFtpPath: Creates a valid FTP path by appending the specified segments to this string

    Creates a valid FTP path by appending the specified segments to this string This string The path segments to append A valid FTP path
    using System;
    using System.Globalization;
    using System.Text.RegularExpressions;
    
    /// <summary>
    /// Creates a valid FTP path by appending the specified segments to this string
    /// </summary>
    /// <param name="path">This string</param>
    /// <param name="segments">The path segments to append</param>
    /// <returns>A valid FTP path</returns>
    public static string GetFtpPath(this string path, params string[] segments)
    {
        foreach (string part in segments)
        {
            if (part != null)
            {
                if (path.Length > 0 && !path.EndsWith("/"))
                    path += "/";
                path += Regex.Replace(part.Replace('\\', '/'), "[/]+", "/").TrimEnd('/');
            }
        }
    
        if (path.Length == 0)
            path = "/";
    
        return path;
    }
    • Public Snippets
    • Channels Snippets