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

FtpHelper.isFolderPresent returns false even tough the folder exists on the ftp server #1528

Closed
bsteinemann opened this issue Apr 25, 2017 · 0 comments

Comments

@bsteinemann
Copy link
Contributor

Description

I want to use the FtpHelper to deploy my build output to my web server. But the FtpHelper seems to be broken. I tried to use the function FtpHelper.uploadAFolder which did only work when I uploaded the folder into the root directory or the one level below (/subdirectory).

I received the following error message:

System.Net.WebException: Der Remoteserver hat einen Fehler zurückgegeben: (550)
Datei nicht verfügbar (z.B. nicht gefunden oder kein Zugriff).

I tracked the problem down to the method FtpHelper.isFolderPresent which is returning false even tough the folder exists on the server.

// returns false even tough the folder exists
FtpHelper.isFolderPresent  server username pwd  "/upload/myfolder"

Repro steps

FtpHelper.createAFolder server username pwd "/upload"
FtpHelper.createAFolder server username pwd "/upload/mysubdir"
sprintf "/upload/mysubdir exists: %b" (FtpHelper.isFolderPresent server username pwd "/upload/mysubdir")|> trace

Output:

Creating folder /upload
Getting FTP dir contents for
Create folder status: 257 "//upload" directory created.

Creating folder /upload/mysubdir
Getting FTP dir contents for
Create folder status: 257 "//upload/mysubdir" directory created.

Getting FTP dir contents for
/upload/mysubdir exists: false

Expected behavior

// should return true because the folder exists
FtpHelper.isFolderPresent  server username pwd  "/upload/mysubdir"

Actual behavior

// returns false but the folder exists
FtpHelper.isFolderPresent  server username pwd  "/upload/mysubdir"

Known workarounds

I copied the following code into my F# script:

let inline regexCheck fname ftpContents = Regex.IsMatch(ftpContents, (sprintf @"\s+%s\s+" fname))
let inline private lastSlashPos (str : string) = str.LastIndexOf(@"\") + 1
let inline private getSubstring (fromPos : int) (str : string) (toPos : int) = str.Substring(fromPos, toPos)

let private checkInExistingDirList server user pwd destPath fname = 
    destPath
    |> lastSlashPos
    |> getSubstring 0 destPath
    |> getFtpDirContents server user pwd
    |> regexCheck fname

let isFolderPresent server user pwd (destPath : string) = 
    destPath
    |> lastSlashPos
    |> destPath.Substring
    |> checkInExistingDirList server user pwd destPath

After replacing the backslash with a slash the following line, the isFolderPresent function worked.
In the original code this function returns the position of the last backslash instead of the position of the last slash.

let inline private lastSlashPos (str : string) = str.LastIndexOf(@"/") + 1

Related information

Ftp Server:

  • Windows 2012 Server
  • IIS 8.0
  • .Net 4.6

Client:

  • Windows 7
bsteinemann added a commit to bsteinemann/FAKE that referenced this issue Apr 25, 2017
- lastSlashPos returned the position of last backslash instead of the last slash

Issue: fsprojects#1528
@matthid matthid closed this as completed May 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants