Created
April 9, 2015 09:50
-
-
Save vbfox/3bc2a7ad9db9b26fe70a to your computer and use it in GitHub Desktop.
Use WinSCP to upload a local directory by FTP in a Fake script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r @"../packages/WinSCP/lib/WinSCPnet.dll" | |
open WinSCP | |
open System | |
open System.IO | |
type FtpServer = | |
{ | |
HostName : string | |
UserName : string | |
Password : string | |
} | |
let private nugetExecutablePath = | |
lazy ( | |
let assemblyDir = Path.GetDirectoryName(typedefof<Session>.Assembly.Location) | |
Path.Combine(assemblyDir, "..", "content", "WinSCP.exe") | |
) | |
let private createSessionOptions server = | |
let options = new SessionOptions() | |
options.Protocol <- Protocol.Ftp | |
options.FtpMode <- FtpMode.Active | |
options.HostName <- server.HostName | |
options.UserName <- server.UserName | |
options.Password <- server.Password | |
options | |
let uploadAFolder localDir remoteDir server = | |
use session = new Session() | |
session.ExecutablePath <- nugetExecutablePath.Value | |
session.Open (server |> createSessionOptions) | |
let localPath = Path.Combine(localDir, "*") | |
let result = session.PutFiles(localPath, remoteDir) | |
if not result.IsSuccess then | |
let exceptions = result.Failures |> Seq.map (fun e -> e :> Exception) | |
raise (new AggregateException(exceptions)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment