public void RemoveFile(string fileName) { if (WININET.FtpDeleteFile(this._hConnect, fileName) == 0) { this.Error(); } }
public void RenameFile(string existingFile, string newFile) { if (WININET.FtpRenameFile(this._hConnect, existingFile, newFile) == 0) { this.Error(); } }
public void PutFile(string localFile, string remoteFile) { if (WININET.FtpPutFile(this._hConnect, localFile, remoteFile, 2, IntPtr.Zero) == 0) { this.Error(); } }
public void RemoveDirectory(string directory) { if (WININET.FtpRemoveDirectory(this._hConnect, directory) == 0) { this.Error(); } }
public void SetCurrentDirectory(string directory) { if (WININET.FtpSetCurrentDirectory(this._hConnect, directory) == 0) { this.Error(); } }
public long GetFileSize(string file) { IntPtr hConnect = new IntPtr(WININET.FtpOpenFile(this._hConnect, file, 0x80000000, 2, IntPtr.Zero)); if (hConnect == IntPtr.Zero) { this.Error(); } else { try { int dwFileSizeHigh = 0; int num2 = WININET.FtpGetFileSize(hConnect, ref dwFileSizeHigh); return((dwFileSizeHigh << 0x20) | num2); } catch (Exception) { this.Error(); } finally { WININET.InternetCloseHandle(hConnect); } } return(0L); }
private List <string> List(string mask, bool onlyDirectories) { List <string> list2; WINAPI.WIN32_FIND_DATA findFileData = new WINAPI.WIN32_FIND_DATA(); IntPtr hInternet = WININET.FtpFindFirstFile(this._hConnect, mask, ref findFileData, 0x4000000, IntPtr.Zero); try { List <string> list = new List <string>(); if (hInternet == IntPtr.Zero) { if (Marshal.GetLastWin32Error() != 0x12) { this.Error(); } return(list); } if (onlyDirectories && ((findFileData.dfFileAttributes & 0x10) == 0x10)) { list.Add(new string(findFileData.fileName).TrimEnd(new char[1])); } else if (!onlyDirectories) { list.Add(new string(findFileData.fileName).TrimEnd(new char[1])); } for (findFileData = new WINAPI.WIN32_FIND_DATA(); WININET.InternetFindNextFile(hInternet, ref findFileData) != 0; findFileData = new WINAPI.WIN32_FIND_DATA()) { if (onlyDirectories && ((findFileData.dfFileAttributes & 0x10) == 0x10)) { list.Add(new string(findFileData.fileName).TrimEnd(new char[1])); } else if (!onlyDirectories) { list.Add(new string(findFileData.fileName).TrimEnd(new char[1])); } } if (Marshal.GetLastWin32Error() != 0x12) { this.Error(); } list2 = list; } finally { if (hInternet != IntPtr.Zero) { WININET.InternetCloseHandle(hInternet); } } return(list2); }
public void CreateDirectory(string path) { if (WININET.FtpCreateDirectory(this._hConnect, path) == 0) { this.Error(); } }
public void GetFile(string remoteFile, string localFile, bool failIfExists) { if (WININET.FtpGetFile(this._hConnect, remoteFile, localFile, failIfExists, 0x80, 2, IntPtr.Zero) == 0) { this.Error(); } }
public string SendCommand(string cmd) { int num; string str; IntPtr ftpCommand = new IntPtr(); if (((str = cmd) != null) && (str == "PASV")) { num = WININET.FtpCommand(this._hConnect, false, 1, cmd, IntPtr.Zero, ref ftpCommand); } else { num = WININET.FtpCommand(this._hConnect, false, 1, cmd, IntPtr.Zero, ref ftpCommand); } int capacity = 0x2000; if (num == 0) { this.Error(); } else if (ftpCommand != IntPtr.Zero) { StringBuilder buffer = new StringBuilder(capacity); int bytesRead = 0; while ((WININET.InternetReadFile(ftpCommand, buffer, capacity, ref bytesRead) == 1) && (bytesRead > 1)) { } return(buffer.ToString()); } return(""); }
public bool DirectoryExists(string path) { bool flag; WINAPI.WIN32_FIND_DATA findFileData = new WINAPI.WIN32_FIND_DATA(); IntPtr hInternet = WININET.FtpFindFirstFile(this._hConnect, path, ref findFileData, 0x4000000, IntPtr.Zero); try { if (hInternet == IntPtr.Zero) { return(false); } flag = true; } finally { if (hInternet != IntPtr.Zero) { WININET.InternetCloseHandle(hInternet); } } return(flag); }
private string InternetLastResponseInfo(ref int code) { int capacity = 0x2000; StringBuilder buffer = new StringBuilder(capacity); WININET.InternetGetLastResponseInfo(ref code, buffer, ref capacity); return(buffer.ToString()); }
public string GetCurrentDirectory() { int capacity = 0x105; StringBuilder currentDirectory = new StringBuilder(capacity); if (WININET.FtpGetCurrentDirectory(this._hConnect, currentDirectory, ref capacity) == 0) { this.Error(); return(null); } return(currentDirectory.ToString()); }
public void Open() { if (string.IsNullOrEmpty(this._host)) { _isconnected = false; throw new ArgumentNullException("Host"); } this._hInternet = WININET.InternetOpen(Environment.UserName, 0, null, null, 4); _isconnected = true; if (this._hInternet == IntPtr.Zero) { _isconnected = false; this.Error(); } }
public void Dispose() { if (!this._disposed) { if (this._hConnect != IntPtr.Zero) { WININET.InternetCloseHandle(this._hConnect); } if (this._hInternet != IntPtr.Zero) { WININET.InternetCloseHandle(this._hInternet); } this._hInternet = IntPtr.Zero; this._hConnect = IntPtr.Zero; this._disposed = true; GC.SuppressFinalize(this); } }
public void Login(string username, string password) { if (username == null) { _isconnected = false; throw new ArgumentNullException("username"); } if (password == null) { _isconnected = false; throw new ArgumentNullException("password"); } this._hConnect = WININET.InternetConnect(this._hInternet, this._host, this._port, username, password, 1, 0x8000000, IntPtr.Zero); _isconnected = true; if (this._hConnect == IntPtr.Zero) { _isconnected = false; this.Error(); } }
public FtpFileInfo[] GetFiles(string mask) { FtpFileInfo[] infoArray; WINAPI.WIN32_FIND_DATA findFileData = new WINAPI.WIN32_FIND_DATA(); IntPtr hInternet = WININET.FtpFindFirstFile(this._hConnect, mask, ref findFileData, 0x4000000, IntPtr.Zero); try { List <FtpFileInfo> list = new List <FtpFileInfo>(); if (hInternet == IntPtr.Zero) { if (Marshal.GetLastWin32Error() != 0x12) { this.Error(); } return(list.ToArray()); } if ((findFileData.dfFileAttributes & 0x10) != 0x10) { FtpFileInfo item = new FtpFileInfo(this, new string(findFileData.fileName).TrimEnd(new char[1])) { LastAccessTime = findFileData.ftLastAccessTime.ToDateTime(), LastWriteTime = findFileData.ftLastWriteTime.ToDateTime(), CreationTime = findFileData.ftCreationTime.ToDateTime(), Attributes = (FileAttributes)findFileData.dfFileAttributes }; list.Add(item); } for (findFileData = new WINAPI.WIN32_FIND_DATA(); WININET.InternetFindNextFile(hInternet, ref findFileData) != 0; findFileData = new WINAPI.WIN32_FIND_DATA()) { if ((findFileData.dfFileAttributes & 0x10) != 0x10) { FtpFileInfo info2 = new FtpFileInfo(this, new string(findFileData.fileName).TrimEnd(new char[1])) { LastAccessTime = findFileData.ftLastAccessTime.ToDateTime(), LastWriteTime = findFileData.ftLastWriteTime.ToDateTime(), CreationTime = findFileData.ftCreationTime.ToDateTime(), Attributes = (FileAttributes)findFileData.dfFileAttributes }; list.Add(info2); } } if (Marshal.GetLastWin32Error() != 0x12) { this.Error(); } infoArray = list.ToArray(); } finally { if (hInternet != IntPtr.Zero) { WININET.InternetCloseHandle(hInternet); } } return(infoArray); }