none
Move files between folders in remote ftp server

    Question

  • Hi,

    How can I move files between folder in FTP folders?
    I have to pick up/download the file from client ftp server, process it at our end, after processing, I have to move the file to Archive folder in FTP server. Insted of deleting file, i have to move it to archive folder in cleint ftp. How can I move file from one to another folder in FTP server?

    Thank you for your help in advance,

    Siv

    Tuesday, July 05, 2011 3:04 AM

Answers

  • You cant do it directly in a single task you have to use separate tasks

    1. Receive files
    2. Delete remote files (If you want to remove it from the server as well)
    3. Send files
    4. Delete local files (FTP Task) Or Delete file (File System Task)

    or u can use the script task to write your own custom script to do the same using FtpWebRequest and System.IO.File.Delete("");


    --------------------------------------------------------

    Surender Singh Bhadauria

     

    • Marked as answer by Eileen Zhao Wednesday, August 10, 2011 9:38 AM
    Tuesday, July 05, 2011 4:19 AM

All replies

  • You cant do it directly in a single task you have to use separate tasks

    1. Receive files
    2. Delete remote files (If you want to remove it from the server as well)
    3. Send files
    4. Delete local files (FTP Task) Or Delete file (File System Task)

    or u can use the script task to write your own custom script to do the same using FtpWebRequest and System.IO.File.Delete("");


    --------------------------------------------------------

    Surender Singh Bhadauria

     

    • Marked as answer by Eileen Zhao Wednesday, August 10, 2011 9:38 AM
    Tuesday, July 05, 2011 4:19 AM
  • That is incorrect. You can move a file using the 'rename' command:

    To move a file to another directory, type "rename [filename] [new/path/to/filename]". The file should now be located in the directory you specified.

    Example: rename test.html mydir/test.html (where "mydir" is a sub-directory of the directory test.html is located in)

    Thursday, October 04, 2012 6:03 PM
  • That is incorrect. You can move a file using the 'rename' command:

    To move a file to another directory, type "rename [filename] [new/path/to/filename]". The file should now be located in the directory you specified.

    Example: rename test.html mydir/test.html (where "mydir" is a sub-directory of the directory test.html is located in)

    How do you send this command with the standard SSIS FTP Task ? This is impossible. Perhaps if you use some kind of shell, it is possible.

    SSIS Tasks Components Scripts Services | http://www.cozyroc.com/

    Sunday, October 07, 2012 11:03 PM
  • LOOK AT THIS., I TRY TO MOVE ALL TXT FILE TO ARCHIVE

    string[] filetxts = GetFileListtxt();
                try {
                    foreach (string movefiletxt in filetxts)
                    {

                        movefilemethod(movefiletxt);
                    }
                
                }
                catch (Exception xn) {}

    public void movefilemethod (string movefilename)
                {
                    string date = DateTime.Now.ToString("ddmmyyhhmms");

                    NetworkCredential User = new NetworkCredential(usernametxt.Text, passwordftp.Text);
                    FtpWebRequest Wr = (FtpWebRequest)FtpWebRequest.Create("ftp://" + Ftpservertxt.Text + "/" + directoryftp.Text + movefilename);
                    Wr.UseBinary = true;
                    Wr.Method = WebRequestMethods.Ftp.Rename;
                    Wr.Credentials = User;
                    Wr.RenameTo = "/" + archieveftp.Text + date + movefilename;
                    Wr.GetResponse().Close();
                   // MessageBox.Show("Move File Successfully");

                }

    public string[] GetFileListtxt()
            {
                string[] downloadFiles;
                StringBuilder result = new StringBuilder();
                WebResponse response = null;
                StreamReader reader = null;
                try
                {
                    FtpWebRequest reqFTP;
                    reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + Ftpservertxt.Text + "/" + directoryftp.Text + "*.txt"));
                    reqFTP.UseBinary = true;
                    reqFTP.Credentials = new NetworkCredential(usernametxt.Text, passwordftp.Text);
                    reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
                    reqFTP.Proxy = null;
                    reqFTP.KeepAlive = false;
                    reqFTP.UsePassive = false;
                    response = reqFTP.GetResponse();
                    reader = new StreamReader(response.GetResponseStream());
                    string line = reader.ReadLine();
                    while (line != null)
                    {
                        result.Append(line);
                        result.Append("\n");
                        line = reader.ReadLine();
                    }
                    // to remove the trailing '\n'
                    result.Remove(result.ToString().LastIndexOf('\n'), 1);
                    return result.ToString().Split('\n');
                }
                catch (Exception ex)
                {
                    if (reader != null)
                    {
                        reader.Close();
                    }
                    if (response != null)
                    {
                        response.Close();
                    }
                    downloadFiles = null;
                    return downloadFiles;
                }
            }

    ANY QUESTION? JUST EMAIL ME IKHSANSAIDI@GMAIL.COM

    HOPE CAN HELP YOU ..

    THANKS.,

    Tuesday, November 19, 2013 3:28 PM