cd command in script fails to change directory

Advertisement

Jowarri
Joined:
Posts:
3
Location:
Minnesota

cd command in script fails to change directory

Hello,

I'm stumped - I've searched the forums, looked at commands, and can't explain this behavior.

The process is simple: Windows scheduler calls a batch file that makes the Winscp script then calls winscp with it. In the script, we change to a directory, get those files, delete those files, exit.

Where the fault comes in is with the cd command. It seems to refuse to change to the named directory. I've tried it with and without paths.
From my reading, perhaps I need to disable the directory caching - but we're not using a stored session, so I don't see how I can do that via command line.

Batch file:
rem ftp grab process
  echo *** %date% %time% Starting Pull >> log\winscp-gd.log
  echo option batch abort > log\winscp-gd.winscp
  echo option confirm off >> log\winscp-gd.winscp
  echo option transfer binary >> log\winscp-gd.winscp
  echo open ftp://user@site.com:password@site.com >> log\winscp-gd.winscp
  echo pwd >> log\winscp-gd.winscp
  echo cd /bww >> log\winscp-gd.winscp
  echo pwd >> log\winscp-gd.winscp
  echo get *.csv -delete >> log\winscp-gd.winscp
  echo exit >> log\winscp-gd.winscp
  c:\Progra~1\WinSCP\winscp.com /script="log\winscp-gd.winscp" /log=log\winscp-gd.log > log\winscp-gd.out
The Log:
*** Fri 10/18/2013 10:45:00.01 Starting BWW Pull 
. 2013-10-18 10:45:00.093 --------------------------------------------------------------------------
. 2013-10-18 10:45:00.093 WinSCP Version 5.1.7 (Build 3446) (OS 6.0.6002 Service Pack 2)
. 2013-10-18 10:45:00.093 Configuration: HKEY_CURRENT_USER\Software\Martin Prikryl\WinSCP 2\
. 2013-10-18 10:45:00.093 Local account: LIL\fsadmin
. 2013-10-18 10:45:00.093 Working directory: C:\Footprint Integrations\Sandbox
. 2013-10-18 10:45:00.093 Process ID: 7940
. 2013-10-18 10:45:00.093 Command-line: "c:\Progra~1\WinSCP\WinSCP.exe" /console=517 /consoleinstance=_4100_715 "/script=log\winscp-gd.winscp" "/log=log\winscp-gd.log" 
. 2013-10-18 10:45:00.093 Time zone: Current: GMT-5, Standard: GMT-6, DST: GMT-5, DST Start: 3/10/2013, DST End: 11/3/2013
. 2013-10-18 10:45:00.093 Login time: Friday, October 18, 2013 10:45:00 AM
. 2013-10-18 10:45:00.093 --------------------------------------------------------------------------
. 2013-10-18 10:45:00.093 Session name: user@site.com@site.com (Ad-Hoc session)
. 2013-10-18 10:45:00.093 Host name: site.com (Port: 21)
. 2013-10-18 10:45:00.094 User name: user@site.com (Password: Yes, Key file: No)
. 2013-10-18 10:45:00.094 Tunnel: No
. 2013-10-18 10:45:00.094 Transfer Protocol: FTP
. 2013-10-18 10:45:00.094 Ping type: C, Ping interval: 30 sec; Timeout: 15 sec
. 2013-10-18 10:45:00.094 Proxy: none
. 2013-10-18 10:45:00.094 FTP: FTPS: None; Passive: Yes [Force IP: A]; List all: A
. 2013-10-18 10:45:00.094 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2013-10-18 10:45:00.094 Cache directory changes: Yes, Permanent: Yes
. 2013-10-18 10:45:00.094 DST mode: 1; Timezone offset: 0h 0m
. 2013-10-18 10:45:00.094 --------------------------------------------------------------------------
. 2013-10-18 10:45:00.095 Connecting to site.com ...
. 2013-10-18 10:45:00.179 Connected with site.com. Waiting for welcome message...
< 2013-10-18 10:45:00.274 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
< 2013-10-18 10:45:00.274 220-You are user number 1 of 50 allowed.
< 2013-10-18 10:45:00.274 220-Local time is now 10:45. Server port: 21.
< 2013-10-18 10:45:00.274 220-This is a private system - No anonymous login
< 2013-10-18 10:45:00.274 220-IPv6 connections are also welcome on this server.
< 2013-10-18 10:45:00.274 220 You will be disconnected after 20 minutes of inactivity.
> 2013-10-18 10:45:00.274 USER user@site.com
< 2013-10-18 10:45:00.348 331 User user@site.com OK. Password required
> 2013-10-18 10:45:00.348 PASS *********
< 2013-10-18 10:45:00.483 230 OK. Current restricted directory is /
> 2013-10-18 10:45:00.483 SYST
< 2013-10-18 10:45:00.558 215 UNIX Type: L8
> 2013-10-18 10:45:00.558 FEAT
< 2013-10-18 10:45:00.635 211-Extensions supported:
< 2013-10-18 10:45:00.635  EPRT
< 2013-10-18 10:45:00.635  IDLE
< 2013-10-18 10:45:00.635  MDTM
< 2013-10-18 10:45:00.635  SIZE
< 2013-10-18 10:45:00.646  MFMT
< 2013-10-18 10:45:00.646  REST STREAM
< 2013-10-18 10:45:00.646  MLST type*;size*;sizd*;modify*;UNIX.mode*;UNIX.uid*;UNIX.gid*;unique*;
< 2013-10-18 10:45:00.646  MLSD
< 2013-10-18 10:45:00.646  AUTH TLS
< 2013-10-18 10:45:00.646  PBSZ
< 2013-10-18 10:45:00.646  PROT
< 2013-10-18 10:45:00.646  ESTA
< 2013-10-18 10:45:00.646  PASV
< 2013-10-18 10:45:00.646  EPSV
< 2013-10-18 10:45:00.646  SPSV
< 2013-10-18 10:45:00.646  ESTP
< 2013-10-18 10:45:00.646 211 End.
. 2013-10-18 10:45:00.646 Connected
. 2013-10-18 10:45:00.646 --------------------------------------------------------------------------
. 2013-10-18 10:45:00.646 Using FTP protocol.
. 2013-10-18 10:45:00.646 Doing startup conversation with host.
> 2013-10-18 10:45:00.646 PWD
< 2013-10-18 10:45:00.718 257 "/" is your current location
. 2013-10-18 10:45:00.719 Getting current directory name.
. 2013-10-18 10:45:00.719 Startup conversation with host finished.
< 2013-10-18 10:45:00.719 Script: Active session: [1] user@site.com@site.com
> 2013-10-18 10:45:00.719 Script: pwd 
< 2013-10-18 10:45:00.719 Script: /
> 2013-10-18 10:45:00.719 Script: cd /bww 
. 2013-10-18 10:45:00.719 Cached directory change via "/bww" to "/".
. 2013-10-18 10:45:00.719 Getting current directory name.
< 2013-10-18 10:45:00.719 Script: /
> 2013-10-18 10:45:00.719 Script: pwd 
< 2013-10-18 10:45:00.719 Script: /
> 2013-10-18 10:45:00.720 Script: get *.csv -delete 
. 2013-10-18 10:45:00.720 Retrieving directory listing...
> 2013-10-18 10:45:00.720 TYPE A
< 2013-10-18 10:45:00.797 200 TYPE is now ASCII
> 2013-10-18 10:45:00.797 PASV
< 2013-10-18 10:45:00.878 227 Entering Passive Mode (184,168,112,123,48,87)
> 2013-10-18 10:45:00.878 MLSD
< 2013-10-18 10:45:01.028 150 Accepted data connection
< 2013-10-18 10:45:01.029 226-Options: -a -l 
< 2013-10-18 10:45:01.029 226 4 matches total
. 2013-10-18 10:45:01.029 type=cdir;sizd=4096;modify=20130915125822;UNIX.mode=0755;UNIX.uid=505;UNIX.gid=504;unique=1egbee3b1; .
. 2013-10-18 10:45:01.029 type=pdir;sizd=4096;modify=20130915125822;UNIX.mode=0755;UNIX.uid=505;UNIX.gid=504;unique=1egbee3b1; ..
. 2013-10-18 10:45:01.029 type=file;size=11;modify=20131004043322;UNIX.mode=0600;UNIX.uid=505;UNIX.gid=504;unique=1egbee56e; .ftpquota
. 2013-10-18 10:45:01.029 type=dir;sizd=4096;modify=20131018152112;UNIX.mode=0755;UNIX.uid=505;UNIX.gid=504;unique=1egbee3b2; bww
. 2013-10-18 10:45:01.029 Directory listing successful
. 2013-10-18 10:45:01.029 ..;D;0;1899-12-30T05:00:00.000Z;"" [0];"" [0];---------;0
. 2013-10-18 10:45:01.029 .ftpquota;-;11;2013-10-04T04:33:22.000Z;"505" [0];"504" [0];rw-------;2
. 2013-10-18 10:45:01.029 bww;D;-1;2013-10-18T15:21:12.000Z;"505" [0];"504" [0];rwxr-xr-x;0
> 2013-10-18 10:45:01.032 Script: exit 
. 2013-10-18 10:45:01.032 Script: Exit code: 0
. 2013-10-18 10:45:01.038 Disconnected from server

* I've looked in the registry (per the docs) to see if there was a setting there for caching directories - didn't see it.
* This started happening with a 4* version of WinSCP, and the update to current version didn't change it.
* This used to work just fine. Worked for over a year. The behavior started about 2 weeks ago.
* I tried to access the tracker link for WinSCP to see if it was a known bug, but I got an error message (I'm probably not allowed in there)

Here's the oddest twist: If I run this directly (logged in as Admin), it works. When called from the Scheduler (as Admin), it fails. I don't see how that should make a difference, but I'll share it in the interest of full disclosure. Should what user the script is called as matter? Ultimately, it needs to work from Scheduler, and I'm willing to change settings/scripts to make that happen.

Thanks in advance!

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: cd command in script fails to change directory

It seems that the cache is corrupted. Remove HKEY_CURRENT_USER\Software\Martin Prikryl\WinSCP 2\Configuration\CDCache from LIL\fsadmin registry hive.

Reply with quote

Jowarri
Joined:
Posts:
3
Location:
Minnesota

Thank you for the response.

I had deleted the key previously here (https://winscp.net/forum/viewtopic.php?t=5427) without luck. Just in case I did it wrong, I had another administrator monitor my change this time, and the result was still the same:

> 2013-10-21 13:45:00.752 Script: pwd 
< 2013-10-21 13:45:00.752 Script: /
> 2013-10-21 13:45:00.752 Script: cd /bww 
. 2013-10-21 13:45:00.753 Cached directory change via "/bww" to "/".
. 2013-10-21 13:45:00.753 Getting current directory name.
< 2013-10-21 13:45:00.753 Script: /
> 2013-10-21 13:45:00.753 Script: pwd 
< 2013-10-21 13:45:00.753 Script: /

Any other ideas? Even some crazy work-arounds? We just need it to work.

Reply with quote

Jowarri

Did I do it right? That's why I had a second admin screen share with me when I did it the second time. We searched the entire hive for 'CDCache' and removed every instance of it, just in case.

I'll try the command line switch. I don't remember that being an option when I first wrote it!

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum