Showing posts with label command. Show all posts
Showing posts with label command. Show all posts

Thursday, March 29, 2012

FTP Task - GET Command

I am working with an odd FTP site that is using a custom pointer file (denoted by a .LMP) extension to provide pointers to dynamic data. To understand the gist, the FTP site will have a list such as:

FileName Size
SomeFile.gz.lmp 0 bytes

In order to obtain the actual file, they want me to run the following command (in BINARY mode only):

GET SomeFile.gz

If I run this command from an command prompt, the file downloads after a few seconds with a size around 3 or 4 MB.

So I need to connect to an FTP site inside of an SSIS project, grab all of the files, strip off the .LMP extension and then perform a GET on each file (RETR does not work). The nI have to gunzip each file prior to finally accessing the connects therein.

Is there any way of accomplishing this task within SSIS or do I have to create some separate shell application?

Thank you!


I don't have any suggestions for getting the list of files, other than a script task.

You could use FOR loop container to iterate the list of file names, once you have it, with an expression on the filename to strip off the .LMP extension.

Check this thread for some unzip ideas:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1150176&SiteID=1

|||

Here is a thread with the script task to loop through a folder on the ftp server. You can just put code in to search for files with the .lmp extension and strip them off where it says "whatever operation you need to do to find the correct file"......

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=783836&SiteID=1

|||I ended up determining that the problem was due to an incompatability between SSIS FTP and Unix. I have posted my solution here:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2177793&SiteID=1&mode=1

FTP Task - GET Command

I am working with an odd FTP site that is using a custom pointer file (denoted by a .LMP) extension to provide pointers to dynamic data. To understand the gist, the FTP site will have a list such as:

FileName Size
SomeFile.gz.lmp 0 bytes

In order to obtain the actual file, they want me to run the following command (in BINARY mode only):

GET SomeFile.gz

If I run this command from an command prompt, the file downloads after a few seconds with a size around 3 or 4 MB.

So I need to connect to an FTP site inside of an SSIS project, grab all of the files, strip off the .LMP extension and then perform a GET on each file (RETR does not work). The nI have to gunzip each file prior to finally accessing the connects therein.

Is there any way of accomplishing this task within SSIS or do I have to create some separate shell application?

Thank you!


I don't have any suggestions for getting the list of files, other than a script task.

You could use FOR loop container to iterate the list of file names, once you have it, with an expression on the filename to strip off the .LMP extension.

Check this thread for some unzip ideas:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1150176&SiteID=1

|||

Here is a thread with the script task to loop through a folder on the ftp server. You can just put code in to search for files with the .lmp extension and strip them off where it says "whatever operation you need to do to find the correct file"......

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=783836&SiteID=1

|||I ended up determining that the problem was due to an incompatability between SSIS FTP and Unix. I have posted my solution here:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2177793&SiteID=1&mode=1

Monday, March 26, 2012

ftp command help

I need to schedule copying of files to an ftp share using a SQL agent
job..but i dont know how to do that in one step
Say for eg: the source of files are on \\computerA\share1\*.*
and the destination is an ftp site ftp.x.com with a username and password
And i want to run this job on say computerB.
Then what would be the command ?
ThanksYou can either
1) create a DTS package (FTP task) then schedule the job by using
'dtsrun' command in the job.
2) use native ftp cmds in the job (jobs steps in an order). e.g.
ftp ftp.x.com
cd (to the location)
put <file>
dir (check if the file there)
close (close the connection)
bye
Mel

ftp command help

I need to schedule copying of files to an ftp share using a SQL agent
job..but i dont know how to do that in one step
Say for eg: the source of files are on \\computerA\share1\*.*
and the destination is an ftp site ftp.x.com with a username and password
And i want to run this job on say computerB.
Then what would be the command ?
ThanksYou can either
1) create a DTS package (FTP task) then schedule the job by using
'dtsrun' command in the job.
2) use native ftp cmds in the job (jobs steps in an order). e.g.
ftp ftp.x.com
cd (to the location)
put <file>
dir (check if the file there)
close (close the connection)
bye
Mel

Monday, March 19, 2012

From Command window output to a text file

Hi,

I want to output from the database, throught the command prompt window and into a text file. I have found a command called bcp command, i have used it and it works just fine . However, i have a problem. The problem is that by default it outputs into the file using tab delimited form. Each column is seperated by a tab. Is there any way , either from the query analyzer onwards or from the bcp command to output the data without the tabs inbetween?

Thank you
George

Check BCP- Specifying Field and Row Terminators in BOL.

Madhu

|||HI,

i did my search before posting , however, the only part i could find similar to my problem was :

terminating character Indicated by

Tab

\t

This is the default field terminator.

Newline character

\n

This is the default row terminator.

Carriage return/line feed

\r

Backslash1

\\

Null terminator (nonvisible terminator)2

\0

Any printable character (control characters are not printable, except null, tab, newline, and carriage return)

(*, A, t, l, and so on)

String of up to 10 printable characters, including some or all of the terminators listed earlier

(**\t**, end, !!!!!!!!!!, \t—\n, and so on)


There is a lot about terminating characters,however, NOTHING on NO charactersat all. I want to tab inbetween, no backslash,no space, no nothing. How can i do that?

Thank you
George|||

i guess i am not clear with the requirement. is it that u want to have a o/p file having Column1+column2+colum3 etc ect without any delimitter?

Madhu

|||hi,

exactly. This is the output with tab delimited format.

vvvXXXXXXXXXXXXXXXXXXXXXX 20071112 h 0000000000005555,70 066,50000
abcXXXXXXXXXXXXXXXXXXXXXX 19000101 y 0454545454523456,45 077,30000
xyzcccXXXXXXXXXXXXXXXXXXX 19000101 x 0000000000003456,00 077,99865
fXXXXXXXXXXXXXXXXXXXXXXXX 20030302 6 0000000000232323,45 005,00000

I want the output to have to tabs , as shown below:

vvvXXXXXXXXXXXXXXXXXXXXXX20071112h0000000000005555,70066,50000
abcXXXXXXXXXXXXXXXXXXXXXX19000101y0454545454523456,45077,30000
xyzcccXXXXXXXXXXXXXXXXXXX19000101x0000000000003456,00077,99865
fXXXXXXXXXXXXXXXXXXXXXXXX2003030260000000000232323,45005,00000

Columns values should not be seperated by tabs. Any thoughts?

Thank you
George|||

use QueryOut option with BCP

Eg.

C:\>bcp "Select col1+col2 from Tablename" queryout 2.txt -T -c

Madhu

|||Hi,

I am already using queryout in my command. the command is below:

C:\>bcp "select ltrim(rtrim(char25))+replicate ('X',25-len(char25)),CONVERT(varc
har(8),dateg,112) as [yyyymmdd],flag1,replace( replicate ('0',19-len(amount)) +
ltrim(rtrim(amount)),'.',','),replace(replicate ('0',9-len(dperc)) + ltrim(rtrim
(dperc)),'.',',') from Bank_Info.dbo.ddd" queryout c:\xxxx\replicate_replace.txt -c -U sax -S KARAFOKAS -C 1252 -P passwsax

I am also using -c which assumes tab delimited as default.|||

c:\sqlcmd -q"select ltrim(rtrim(char25))+replicate ('X',25-len(char25)),CONVERT(varc
har(8),dateg,112) as [yyyymmdd],flag1,replace( replicate ('0',19-len(amount)) +
ltrim(rtrim(amount)),'.',','),replace(replicate ('0',9-len(dperc)) + ltrim(rtrim
(dperc)),'.',',') from Bank_Info.dbo.ddd" -o"c:\xxxx\replicate_replace.txt" -h-1

Check this

if its 2000 replace sqlcmd with OSQL

Madhu

|||

i can get the result as desired in both BCP and SQLCMD.

Madhu

|||Hi,

I dont understand. I want to use bcp command . Can you write the bcp command to use ?

Thank you
George|||

Have you tried with SQLCMD /OSQL . I can get the result as you mentioned using both BCP and SQLCMD. If still you are not able to then the workaround is add a new column to this table (or for that matter create a new table) and update the column with this Value and select that column using QUERYOUT.

Madhu

|||Hi,

I have tried with SQLCMD but it doesnt work. You said you got the same desired result using also bcp. well, what did u do to avoid the field delimeters? Can you copy paste the correct command to use without removing any of my properties/parameters that i have used?

Thank you
George|||Hi,

After a lot of hours i have managed to do what i wanted to . The only way NOT to have field delimiters is to create a format file and use that one in order to run the command. The format file looks like the one below (name: bcp.fmt)

8.0
5
1 SQLCHAR 0 25 "" 1 char25 Greek_BIN
2 SQLCHAR 0 8 "" 2 yyyymmdd Greek_BIN
3 SQLCHAR 0 1 "" 3 flag1 Greek_BIN
4 SQLCHAR 0 19 "" 4 amount Greek_BIN
5 SQLCHAR 0 9 "\r\n" 5 dperc Greek_BIN

As you can see , the field delimiters are empty. The command i used is :

C:\>bcp "select ltrim(rtrim(char25))+replicate ('X',25-len(char25)),CONVERT(varc
har(8),dateg,112) as [yyyymmdd],flag1,replace( replicate ('0',19-len(amount)) +
ltrim(rtrim(amount)),'.',','),replace(replicate ('0',9-len(dperc)) + ltrim(rtrim
(dperc)),'.',',') from Bank_Info.dbo.ddd" queryout c:\xxxx\replicate_replace.tx
t -fc:\xxxx\bcp.fmt -U sax -S KARAFOKAS -C 1252 -P passsax

instead of

C:\>bcp "select ltrim(rtrim(char25))+replicate ('X',25-len(char25)),CONVERT(varc
har(8),dateg,112) as [yyyymmdd],flag1,replace( replicate ('0',19-len(amount)) +
ltrim(rtrim(amount)),'.',','),replace(replicate ('0',9-len(dperc)) + ltrim(rtrim
(dperc)),'.',',') from Bank_Info.dbo.ddd" queryout c:\xxxx\replicate_replace.tx
t -c -U sax -S KARAFOKAS -C 1252 -P passsax

Hope others dont lose 2-3 hours of their time.

Thank you Madhu. I am marking this question sovled and helpful

George

Monday, March 12, 2012

Friday Fun - RunningTotalsAnyone?

If I put this in crystal reports I can manipulate it ok, but actually translating it to a command isn't so easy for me. I'm terrible at cursors and need some help here, pretty pretty please.

I have a table...

CREATE TABLE [dbo].[StagePayment] (
[PaymentID] [uniqueidentifier] NOT NULL ,
[JobID] [uniqueidentifier] NOT NULL ,
[Paid] [bit] NOT NULL ,
[Sequence] [smallint] NOT NULL ,
[Amount] [decimal](10, 2) NOT NULL ,
[Activity] [varchar] (30) NULL ,
[ActivityID] [uniqueidentifier] NULL ,
[DueDate] [datetime] NULL ,
[InvoiceNumber] [varchar] (50) NULL ,
[DueNext] [bit] NOT NULL
) ON [PRIMARY]
GO

Simple example of the data I need to work with...

PayID JobID Paid Sequence Amount DueNext

6094 12 1 1 0.00 0
6B1E 18 1 1 0.00 0
297C 25 1 1 0.00 0
E175 30 1 1 4390.00 0
8CF9 30 1 2 4390.00 0
9168 39 1 1 4400.00 0
59F4 39 1 2 6632.00 0
BCAF 54 1 1 417.50 0
5922 54 0 2 417.50 0
8DA0 68 1 1 2988.00 0
76C5 68 1 2 9958.00 0
0C13 68 1 3 7566.00 0
F3F4 68 1 4 2390.00 0

What I need to accomplish is flagging the DueNext field if the amount due has not been paid. I cannot rely on the Paid field as it's currently user controlled. I need to compare what's due with the total already paid (stored in another table).

So for instance,
Job #68 - the total amount due would be $22902.00

If the customer has paid $15000.00 then Sequence 3, PayID 0C13, should be flagged as DueNext.

Anyone have a very simple example of a running total cursor that I can reference or a better idea of how to work with this? I appreciate any and all suggestions!
Thanks!
abbra_dooYou can do running totals in SQLSVR without cursors, but is it better to handle them in your reporting tool (Crystal Reports, in your case).
Include the total already paid from the other table as a column in your result set. Have Crystal keep the running total and flag records that exceed the total paid.|||You could create function and bind it to the DueNext field. Inside the function you can compare the totals and have the function return either a 1 or a 0 (zero)

Here's an example from BOL

CREATE FUNCTION CubicVolume
-- Input dimensions in centimeters
(@.CubeLength decimal(4,1), @.CubeWidth decimal(4,1),
@.CubeHeight decimal(4,1) )
RETURNS decimal(12,3) -- Cubic Centimeters.
AS
BEGIN
RETURN ( @.CubeLength * @.CubeWidth * @.CubeHeight )
END

This function can then be used anywhere an integer expression is allowed, such as in a computed column for a table:

CREATE TABLE Bricks
(
BrickPartNmbr int PRIMARY KEY,
BrickColor nchar(20),
BrickHeight decimal(4,1),
BrickLength decimal(4,1),
BrickWidth decimal(4,1),
BrickVolume AS
(
dbo.CubicVolume(BrickHeight,
BrickLength, BrickWidth)
)
)

Obviously your logic will differ from this function but essentially it should work the same way you'll just have to have some If...then logic to determine what you want to return.

Best regards|||Thanks blindman but our developers are revamping the application for our users and the DueNext field is new and needs to be populated within the database. Otherwise I'd be real happy as the report was alreay in place and working. Eventually this change is supposed to make life on the payment side of the fence much more intuitive and reports should become easier overall - fingers crossed!
abbra_doo|||Thanks mkal -

I'll read up more on this and see if it'll help.

abbra_doo|||Would it be easier to add a temporary field called RunningTotal to the StagePayment table and insert the tabulated running total for that job then I would only have to compare and flag DueNext as necessary? Sort of like this...

PayID JobID Paid Sequence Amount RunningTotal DueNext

6094 12 1 1 0.00 0.00 0
6B1E 18 1 1 0.00 0.00 0
297C 25 1 1 0.00 0.00 0
E175 30 1 1 4390.00 4390.00 0
8CF9 30 1 2 4390.00 8780.00 0
9168 39 1 1 4400.00 4400.00 0
59F4 39 1 2 6632.00 11032.00 0
BCAF 54 1 1 417.50 417.50 0
5922 54 0 2 417.50 835.00 0
8DA0 68 1 1 2988.00 2988.00 0
76C5 68 1 2 9958.00 12946.00 0
0C13 68 1 3 7566.00 20512.00 0
F3F4 68 1 4 2390.00 22902.00 0

I'm still sort of stuck on getting the runnig total to tally right though so if anyone has thoughts I would love to hear them!
abbra_doo|||I wouldn't use a function for this.

In your case, you need to calculate a running total, which requires a scan of the table. A user-defined function would execute once for every record in your resultset (or more), so 1000 records means 1000 function calls and 1000 scans.

Here is one method of doing this without a cursor:
select StagePayment.JobID,
StagePayment.Sequence,
StagePayment.Amount,
sum(RunningSums.Amount) as RunningSum
from StagePayment
inner join StagePaymen RunningSums
on StagePayment.JobID = RunningSums.JobID
and StagePayment.Sequence >= RunningSums.Sequence
group by StagePayment.JobID,
StagePayment.Sequence,
StagePayment.Amount|||blindman, excellent as usual

next he's gonna ask you for the update statement...

;)|||Sorry, I've been out and I'm just getting back to this.

Thanks a bunch blindman! I was using a <= in my query and getting exactly the same as the Amount and once switched to >= I got the running total! So thanks, thanks, thanks! I was the blind-one in that query! Hahaha!

I ended up creating a temp table and I put all the data from the StagePayment table, plus a running total column, plus the total amount paid column for each job. Then I just updated the temp table and selected the minimum sequence for a job where the amount due (running total field) was less than the amount paid. Spot checked some of the jobs and updated the actual StagePayment table and !!Voila!!, no cursor needed - I really dislike them! Everything looks like it's correct so I think I'm a happy camper!

Thanks again!
Hope you all have a terrific 2007 (Lunar Year of the Fire Pig)!
abbra_doo

Friday, March 9, 2012

Freezes while using sapwd and instancename

I am trying to setup a strong password and instance name to use in WSUS. I
get to the command prompt, and it begin the installation process, but freezes
with 15 seconds remaing
hi,
twackel wrote:
> I am trying to setup a strong password and instance name to use in
> WSUS. I get to the command prompt, and it begin the installation
> process, but freezes with 15 seconds remaing
<WARNING>
this method is not supported... pleas have a look in your task manager if a
process named "setupre.exe" is hanging...
if it is, try killing it, and the setup process should continue..
</WARNING>
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
DbaMgr2k ver 0.12.0 - DbaMgr ver 0.58.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
-- remove DMO to reply