Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Net.FtpClient;
- using System.Net;
- using System.IO;
- namespace MyFTP
- {
- class FTPExample
- {
- private FtpClient _client;
- public void MoveFiles()
- {
- using (FtpClient _client = new FtpClient())
- {
- _client.Host = "xx.xx.xx.xxx";
- _client.Credentials = new NetworkCredential()
- {
- UserName = "xxx",
- Password = "xxxx",
- };
- foreach (var listing in _client.GetListing())
- {
- //get a pattern from database or config to filter files for this "file movement" record (how to implement?)
- if (listing.Type == FtpFileSystemObjectType.File && IsMatch(listing.Name))
- {
- try
- {
- byte[] currentFile = ReadMatchedFile(listing);
- if (currentFile.Length > 0)
- {
- File.WriteAllBytes(@"c:mytestoutputfile.txt", currentFile);
- }
- }
- catch (Exception e)
- {
- }
- }
- }
- }
- }
- private bool IsMatch(string fileName)
- {
- //not implemented.
- return true;
- }
- private byte[] ReadMatchedFile(FtpListItem file)
- {
- byte[] buffer = new byte[file.Size];
- //read data into buffer (not implemented)
- return buffer;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement