[Haskell-cafe] FW: upload file with ftp
Brandon Allbery
allbery.b at gmail.com
Tue Jan 5 12:48:51 UTC 2021
At a guess, you're using a modern FTP client that defaults to passive mode
for compatibility with firewalls, and you'll need to check the docs to see
how to do passive mode with Network.Client.FTP.
On Tue, Jan 5, 2021 at 7:24 AM Kees Bleijenberg <K.Bleijenberg at lijbrandt.nl>
wrote:
> I want to upload a file with ftp using library Network.FTP.Client.
> The OS is Windows 64 and ghc version is 8.6.4.
>
> This is the code:
>
> import System.FilePath.Windows
> import Network.FTP.Client
> import qualified Data.ByteString as B
> ....
> testFtp :: IO (Either String ())
> testFtp = do
> let host = "copecco" -- this is from my hosts file
> username = ****
> pwd = ****
> ftpDir = "registratie"
> fileToSend = "globals.pas" -- a test text file
> putStrLn $ "Connect to " ++ host
> withFTP host 21 $ \h ftpResponse -> do
> print ftpResponse
> if frStatus ftpResponse == Success
> then do
> putStrLn "Connected"
> loginResp <- login h username pwd
> print loginResp
> if frStatus loginResp == Success
> then do
> putStrLn $ "Change directory to " ++ ftpDir
> cwdResp <- cwd h ftpDir
> print cwdResp
> if frStatus cwdResp == Success
> then do
> putStrLn "Read file from disk"
> let ftpFn = takeFileName fileToSend
> fileContents <- B.readFile fileToSend
> putStrLn $ "File size: " ++ show
> (B.length fileContents) ++ " bytes"
> stor h ftpFn fileContents TI
> return $ Right ()
> else return $ Left $ "Ftp error cwd. Code: " ++
> show (frCode ftpResponse)
> else return $ Left $ "Ftp error login. Code: " ++ show
> (frCode ftpResponse)
> else return $ Left $ "Connect to host " ++ host ++ " failed.
> Code:
> " ++ show (frCode ftpResponse)
>
> This is the response:
> Connect to copecco
>
> 220 (vsFTPd 3.0.2)
>
> Connected
>
> 230 Login successful.
>
> Change directory to registratie
>
> 250 Directory successfully changed.
>
> Read file
>
> File size: 27015 bytes
>
> *** Exception: Network.Socket.connect: <socket: 444>: failed (Connection
> timed out (WSAETIMEDOUT))
>
> Everything works fine until the stor commmand.
> When I upload the same file with another ftp client program everything
> works
> (no permission problems).
>
> What is wrong and how do I get the result codes for the stor command?
>
> Kees
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
--
brandon s allbery kf8nh
allbery.b at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20210105/6637faeb/attachment.html>
More information about the Haskell-Cafe
mailing list