[Haskell-cafe] FW: upload file with ftp
Kees Bleijenberg
K.Bleijenberg at lijbrandt.nl
Tue Jan 5 12:23:45 UTC 2021
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
More information about the Haskell-Cafe
mailing list