Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.ArgumentException when calling FtpHelper.uploadAFolder #1785

Closed
usemam opened this issue Feb 16, 2018 · 2 comments
Closed

System.ArgumentException when calling FtpHelper.uploadAFolder #1785

usemam opened this issue Feb 16, 2018 · 2 comments

Comments

@usemam
Copy link

usemam commented Feb 16, 2018

Description

Build script fails to create remote "Content" folder when uploading compiled web-site over to FTP, using FtpHelper.uploadAFolder method.

Repro steps

  1. Create a script that uploads a web-site to FTP server.
  2. Make sure your web-site contains folder named "Content".
  3. Run script.

Expected behavior

Web-site uploaded successfully to remote FTP server.

Actual behavior

Script fails with the exception:

  1. System.ArgumentException: parsing "\s+wwwroot1\Content\s+" - Unrecognized escape sequence \C.
    at System.Text.RegularExpressions.RegexParser.ScanCharEscape()
    at System.Text.RegularExpressions.RegexParser.ScanBasicBackslash()
    at System.Text.RegularExpressions.RegexParser.ScanBackslash()
    at System.Text.RegularExpressions.RegexParser.ScanRegex()
    at System.Text.RegularExpressions.RegexParser.Parse(String re, RegexOptions op)
    at System.Text.RegularExpressions.Regex..ctor(String pattern, RegexOptions options, TimeSpan matchTimeout, Boolean useCache)
    at System.Text.RegularExpressions.Regex.IsMatch(String input, String pattern)
    at Fake.FtpHelper.checkInExistingDirList(String server, String user, String pwd, String destPath, String fname) in D:\code\fake\src\app\FakeLib\FtpHelper.fs:line 90
    at Fake.FtpHelper.createAFolder(String server, String user, String pwd, String destPath) in D:\code\fake\src\app\FakeLib\FtpHelper.fs:line 116
    at Fake.FtpHelper.upload(String server, String user, String pwd, FileSystemInfo fsi, String rootDir) in D:\code\fake\src\app\FakeLib\FtpHelper.fs:line 140
    at [email protected](FileSystemInfo fsi) in D:\code\fake\src\app\FakeLib\FtpHelper.fs:line 134
    at Microsoft.FSharp.Collections.SeqModule.Iterate[T](FSharpFunc2 action, IEnumerable1 source)
    at [email protected](Unit _arg1) in C:\Projects\kopany\build.fsx:line 95
    at Fake.TargetHelper.runSingleTarget(TargetTemplate`1 target) in D:\code\fake\src\app\FakeLib\TargetHelper.fs:line 626

Known workarounds

This code copied from FtpHelper with back-stroke symbols replaced with forward stroke symbol, seems to seal the deal:

module FtpUpload =
let inline private dirNameIsValid (dirName : string) =
let invalidChars = [ "<"; ">"; ":"; """; "/"; "\"; "|"; "?"; "*" ]
let invalidNames =
[ "CON"; "PRN"; "AUX"; "NUL"; "COM1"; "COM2"; "COM3"; "COM4"; "COM5"; "COM6"; "COM7"; "COM8"; "COM9"; "LPT1";
"LPT2"; "LPT3"; "LPT4"; "LPT5"; "LPT6"; "LPT7"; "LPT8"; "LPT9" ]
let invalid1 = List.exists (fun s -> s = dirName.ToUpper()) invalidNames
let invalid2 = List.exists (fun s -> dirName.ToUpper().StartsWith(sprintf "%s." s)) invalidNames
let invalid3 = dirName.EndsWith(" ")
let invalid4 = dirName.EndsWith(".")
let invalid5 = List.exists (fun s -> dirName.Contains(s)) invalidChars
not (invalid1 && invalid2 && invalid3 && invalid4 && invalid5)

let rec uploadAFolder server user pwd (srcPath : string) (rootDir : string) = 
    logfn "Uploading folder %s" srcPath
    let dirInfo = new DirectoryInfo(srcPath)
    if dirInfo.Exists && dirNameIsValid rootDir then 
        dirInfo.GetFileSystemInfos() |> Seq.iter (fun fsi -> upload server user pwd fsi rootDir)

and private upload server user pwd (fsi : FileSystemInfo) (rootDir : string) = 
    match fsi.GetType().ToString() with
    | "System.IO.DirectoryInfo" -> 
        FtpHelper.createAFolder server user pwd rootDir
        FtpHelper.createAFolder server user pwd (sprintf "%s/%s" rootDir fsi.Name)
        uploadAFolder server user pwd fsi.FullName (sprintf "%s/%s" rootDir fsi.Name)
    | "System.IO.FileInfo" -> FtpHelper.uploadAFile server user pwd (sprintf "%s/%s" rootDir fsi.Name) fsi.FullName
    | _ -> logfn "Unknown object found at %A" fsi

Related information

  • Operating system: Windows 7 Pro SP1
  • FAKE 4.64.4
  • .NET Runtime, CoreCLR or Mono Version: .NET Framework 4.5.2
@matthid
Copy link
Member

matthid commented Feb 18, 2018

Is 11712be the commit you are suggesting?

@usemam
Copy link
Author

usemam commented Feb 18, 2018

@matthid Yes, proposed change helped in my case, but I didn't test it extensively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants