Esempio n. 1
0
 /// <summary>
 ///**************************************************/
 /// Them tat ca tap tin va thu muc tai thu muc strFolder tren may tram
 /// vao ListView lsV
 ///**************************************************/
 /// </summary>
 public static void FillLocalListView(ListView lsV, String strFolder)
 {
     //set the new local working directory
     try
     {
         CAPIFunctions.SetCurrentDirectory(strFolder);
     }
     catch (DirectoryNotFoundException e)
     {
         MessageBox.Show("loi, SetCurrentDirectory");
     }
     //re-fill the local list with new directory
     FillLocalListView(lsV);
 }
Esempio n. 2
0
    /// <summary>
    ///**************************************************/
    /// Them tat ca tap tin va thu muc tai thu muc hien hanh tren may tram
    /// vao ListView lsV
    ///**************************************************/
    /// </summary>
    public static void FillLocalListView(ListView lsV)
    {
        string          strFileName;
        WIN32_FIND_DATA FindFileData = new WIN32_FIND_DATA();
        IntPtr          hFindFile;
        int             index = new int();

        lsV.Clear();

        string str = Directory.GetCurrentDirectory();

        if (str.LastIndexOf('\\') == str.Length - 1)
        {
            str += "*";
        }
        else
        {
            str += "\\*";
        }

        hFindFile = CAPIFunctions.FindFirstFile(str, FindFileData);

        if (hFindFile.ToPointer() != null)
        {
            if ((FindFileData.dwFileAttributes & FileAttribute.FILE_ATTRIBUTE_DIRECTORY) == FileAttribute.FILE_ATTRIBUTE_DIRECTORY)
            {
                index       = 0;
                strFileName = FindFileData.cFileName + " <DIR>";
            }
            else
            {
                strFileName = FindFileData.cFileName;

                string temp = "";
                try
                {
                    temp = strFileName.Substring(strFileName.Length - 4, 4);
                }
                catch (Exception e1)
                {
                }

                index = FTPClient.Form1.IndexImage(temp);
            }
            lsV.Items.Add(strFileName, index);

            bool kq;
            while (kq = CAPIFunctions.FindNextFile(hFindFile, FindFileData))
            {
                if ((FindFileData.dwFileAttributes & FileAttribute.FILE_ATTRIBUTE_DIRECTORY) == FileAttribute.FILE_ATTRIBUTE_DIRECTORY)
                {
                    index       = 0;
                    strFileName = FindFileData.cFileName + " <DIR>";
                }
                else
                {
                    strFileName = FindFileData.cFileName;
                    string temp = strFileName.Substring(strFileName.Length - 3, 3);
                    index = FTPClient.Form1.IndexImage(strFileName.Substring(strFileName.Length - 3, 3));
                }
                lsV.Items.Add(strFileName, index);
            }
///            CAPIFunctions.FindClose(hFindFile);
        }
    }
Esempio n. 3
0
    /// <summary>
    /// Upload tat ca cac tap tin va thu muc con ben trong thu muc strFolder
    /// cua may tram len FTP server
    /// Tham so:
    ///  strFolder: ten thu muc muon Upload
    /// </summary>
    private bool _UploadFolder(String strFolder)
    {
        StringBuilder   szPath       = new StringBuilder(256);
        String          arrFolder    = null;
        uint            uiLen        = 256;
        WIN32_FIND_DATA FindFileData = new WIN32_FIND_DATA();
        IntPtr          hFindFile;

        if (CWinINet.FtpSetCurrentDirectory(m_HConnect, strFolder) == false)
        {
            return(false);
        }
        else
        {
            uiLen = 256;
            CWinINet.FtpGetCurrentDirectory(m_HConnect, szPath, ref uiLen);
        }

        try
        {
            Directory.SetCurrentDirectory(strFolder);
        }
        catch (Exception e)
        {
            return(false);
        }

        string str = Directory.GetCurrentDirectory();

        if (str.LastIndexOf('\\') == str.Length - 1) // O dia
        {
            str += "*";
        }
        else // Thu muc
        {
            str += "\\*";
        }

        hFindFile = CAPIFunctions.FindFirstFile(str, FindFileData);
        if (hFindFile.ToPointer() != null)
        {
            // Upload tat ca cac tap tin len FTP server
            if (!((FindFileData.dwFileAttributes & FileAttribute.FILE_ATTRIBUTE_DIRECTORY) == FileAttribute.FILE_ATTRIBUTE_DIRECTORY))
            {
                if (!CWinINet.FtpPutFile(m_HConnect, FindFileData.cFileName, FindFileData.cFileName,
                                         CWinINet.FTP_TRANSFER_TYPE_BINARY, 0))
                {
                    return(false);
                }
                else
                {
                    frm.lbl.Text = szPath + "\\" + FindFileData.cFileName;
                }
            }
            else // Thu muc
            {
                if (FindFileData.cFileName != ".")
                {
                    arrFolder += "|" + FindFileData.cFileName;
                }
            }

            while (CAPIFunctions.FindNextFile(hFindFile, FindFileData))
            {
                if (!((FindFileData.dwFileAttributes & FileAttribute.FILE_ATTRIBUTE_DIRECTORY) == FileAttribute.FILE_ATTRIBUTE_DIRECTORY))
                {
                    if (!CWinINet.FtpPutFile(m_HConnect, FindFileData.cFileName, FindFileData.cFileName,
                                             CWinINet.FTP_TRANSFER_TYPE_BINARY, 0))
                    {
                        return(false);
                    }
                    else
                    {
                        frm.lbl.Text = szPath + "\\" + FindFileData.cFileName;
                    }
                }
                else // Thu muc
                if (FindFileData.cFileName != "..")
                {
                    arrFolder += "|" + FindFileData.cFileName;
                }
            }
            CWinINet.InternetCloseHandle(hFindFile);
            // Upload tat ca cac thu muc ve FTP Server
            if (arrFolder != null)
            {
                string[] arr = arrFolder.Split('|');
                for (int i = 1; i < arr.Length; ++i)
                {
                    try
                    {
                        CWinINet.FtpCreateDirectory(m_HConnect, arr[i]);
                    }
                    catch (FileNotFoundException e)
                    {
                        return(false);
                    }

                    return(_UploadFolder(arr[i]));
                }
            }
            // Tra ve thu muc hien hanh
            uiLen = 256;
            if (CWinINet.FtpGetCurrentDirectory(m_HConnect, szPath, ref uiLen) == false)
            {
                return(false);
            }
            if (CWinINet.FtpSetCurrentDirectory(m_HConnect, szPath.ToString() + "//..") == false)
            {
                return(false);
            }

            try
            {
                Directory.SetCurrentDirectory(Directory.GetCurrentDirectory() + "\\..");
            }
            catch (Exception e)
            {
                return(false);
            }
        }
        return(true);
    }